def setup(**kwargs): connection = MySQLdb.connections.Connection(**kwargs) engine = create_engine('mysql://', creator=lambda: connection, pool_recycle=2)
the "creator" argument is a callable that returns a new connection when the pool needs one. Above, you are pre-connecting a single MySQL connection and returning it from the lambda. Besides producing non- mutexed multithreaded access to the single Connection itself (which may or may not be OK for MySQLdb), it also prevents a new connection from being created once it has been recycled. The previous connection, now closed, is all that's available. The correct form is: def setup(**kwargs): def connect(): return MySQLdb.connections.Connection(**kwargs) engine = create_engine('mysql://', creator=lambda: connect, pool_recycle=2) On Dec 19, 2008, at 6:05 PM, Ken wrote: > > I've created a full test case that should reproduce the error for you. > You'll need to create a database called 'test' on your local machine. > I think I've isolated the problem to the use of the creator keyword > argument, which I use in my application for various reasons. > > http://rafb.net/p/8Ayjxc63.html > > Results in: > > http://rafb.net/p/QPoesQ74.html > > Here are the versions I used to cause this bug: > > mysqld Ver 5.0.67-0ubuntu6 for debian-linux-gnu on i486 ((Ubuntu)) > MySQLdb 1.2.2 > > For sqlalchemy, I've tried 0.5rc4 and 0.4.8; it happens with either > version. > > On Dec 18, 10:11 am, Michael Bayer <mike...@zzzcomputing.com> wrote: >> >> Would need to see how your create_engine() is configured, what >> versions of MySQL/MySQLdb are in use. > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---