I have the following definitions:
def sql_processes(db1, infile_name, z):
cursor = db1.cursor()
print "Processing " + infile_name
PrintLog("Adding " + infile_name + "to MySQL...")
vcf_reader = vcf.Reader(open(infile_name, 'r'))
for record in vcf_reader:
snp_position='_'.join([record.CHROM, str(record.POS)])
ref_F = float(record.INFO['DP4'][0])
ref_R = float(record.INFO['DP4'][1])
alt_F = float(record.INFO['DP4'][2])
alt_R = float(record.INFO['DP4'][3])
AF = (alt_F+alt_R)/(alt_F+alt_R+ref_F+ref_R)
sql_test_query = "SELECT * from snps where snp_pos='" + snp_position + "'"
try:
sql_insert_table = "INSERT INTO snps (snp_pos, " + str(z) + "g) VALUES ('" + snp_position + "', " + str(AF) + ")"
cursor.execute(sql_insert_table)
except db1.IntegrityError, e:
sql_insert_table = "UPDATE snps SET " + str(z) + "g=" + str(AF) + " WHERE snp_pos='" + snp_position + "'";
cursor.execute(sql_insert_table)
db1.commit()
cursor.close()
print "Processing of " + infile_name + "done!"
PrintLog("Added " + infile_name + "to MySQL!")
def extractAF(files_vcf):
z=6
snp_dict=[]
db1 = MS.connect(host="localhost",user="root",passwd="sequentia2",db="SUPER_SNP_calling")
threads = []
for infile_name in sorted(files_vcf):
t = Thread(target = sql_processes, args = (db1, infile_name, z))
threads.append(t)
z+=1
count_t = 1
my_threads = []
for t in threads:
t.start()
my_threads.append(t)
if count_t == 8:
for x in my_threads:
x.join()
my_threads = []
count_t = 0
count_t+=1
The aim here is to read multiple files at the same time and update a MySQL
database. However, this throws the following error:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "./SUPER_mysql4.py", line 457, in sql_processes
cursor.execute(sql_insert_table)
File "/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 202, in execute
self.errorhandler(self, exc, value)
File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
InterfaceError: (0, '')
*** Error in `Segmentation fault (core dumped)
Why is it happening?