The following code is generating transaction errors.
The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.
The larger the gevent pool, the more frequent the errors.
What I do is:
- pool spawn in my main function:
pool.spawn(collector, target_table, source_table, columns_to_copy, sql_filter)
- inside collector function I instantiate a mydb object and setup db connection
def collector( target_table, source_table, columns_to_copy, sql_filter):
mydb = MySQLClass(host=SQL_HOST, database_name='mydb', user=myuser, password=mypw)
.....
mydb.sql_delete(table, sql_where_filter)
note that MySQLClass __init__
is where I actually establish the connection:
class MySQLClass(object):
def __init__(self, host, database_name, user, password ):
self.db = pymssql.connect( host=host,
database=database_name,
user=user,
password=password )
self.cursor=self.db.cursor()
- call to cursor.execute(DELETE) within mydb.my_defined_delete_method
def sql_delete(self, table, sql_filter="" ):
self.cursor.execute("DELETE FROM " + table + " " + sql_filter )
self.db.commit()
return
when multithreading @ 10x this barely ever occurs, when multithreading @ 20+ x this becomes increasingly more frequent.
I thought the error was originating in another part of the code where I actually have a cursor.execute("BEGIN TRAN....")
, but that is rarely the case, if ever.
Any ideas?