python - sqlalchemy + mysql deadlocks -


I insert rows with random data in mysql database. After inserting some rows, hanging on is hanging green. Data printing keeps greenlet running on

It happens with any number of workers (including one), both with mysql-connector and mysqldb drivers. Sqlite works fine.

There is no effect (as I think it is already settled in New Vebvest)

  Diarf patch (): Gagvet import Monkey the https://bugs.launchpad.net/myconnpy/+bug patch_all () # SQLAlchemy import metadata, tables, columns, integer, string, the mysql.connector.connection import MySQLConnection MySQLConnection.get_characterset_info = MySQLConnection.get_charset patch (create_engine) / 712,037 fixed gevent import eggs, sleeping random import randrange time import time class statistics (object): def __init __ (self): self.inserts, self.faults = 0, 0 Def run (self): While this is true: sleep (1) print "% d% d% d"% (time (), self.inserts, self.faults) self.inserts, self.faults = 0, 0 square Hunting (object): Metadata = Metadata () entry = table ('entry', metadata, column ('id', integer, primary_key = true), column ('junk' ', string (128), unique = true) __init __ (self, cs, statistics): self.e = create_engine (CS) self Metadata. Drop_all (auto.e.) self Metadata.create_self (auto.e.) self Data = data def (self, junk, i): print I, 'connect' C = try self.e.connect () print I, 'connect' t = c.begin (): q = self.Entry.insert ( ) .values ​​(junk = junk) c.execute (q) t.commit () self.stats.inserts + = 1 Except exception: Print I, 'Exception:', ET Rollback () Selfkstats Kfaults + = 1 print I Diaf Flood (hunting, I): A, Z, L = Ord ( 'A'), Ord ( "Z") + 1, 100 while true: victim. Add ('' .join (for chr (randrange (a, z)) in xrange (l), i) sleep (0) def main (n_threads, cs): statistics = stats () hunting = hunting (cs , Stats) thread = [eggs (flood, hunting, i) (n_threads)] threads.append (eggs. stats) for xrange [t.join (for t in thread)] #main (2 , 'mysql: // root: root @ localhost / junk') Home (1, 'mysql + mysqlconnector: // root: root @ localhost / junk')   

What is happening


I just forgot to release used connection So, the connecting owens where ever the check-in is not back in the pool. ...

  def add (self, junk, i): print i, 'connect' c = self.e.connect () ... try: ... except the exception : ... Finally: c.close () # & lt; - This bridge is inserted in print I, 'done'    

Comments