There is clearly some facility built into SQLObject for threads - there is the connection pool, which is designed (per the code) to ensure only (at most?) one connection is opened per thread, and a sqlhub member called threadConnection in addition to processConnection. There is also the _connection parameter to each SQLObject call. Perhaps someone who is using SQLObject in a threaded context could share their connection management wisdom.
In fact, I find that ensuring that I "create a connection and only use it in that thread" is not sufficient to eliminate the issues I'm having with SQLObject, MySQLdb, and MySQL. It is not clear to me which of SQLObject or MySQLdb is to blame, but it appears that one of them (probably MySQLdb) is doing something in a non-thread-safe manner. For reference, here is the offending code snippet: sqlhub.processConnection = connectionForURI(connuri) class AAA(SQLObject): class sqlmeta: createSQL = {'mysql': 'ALTER TABLE aa_a ENGINE InnoDB'} cacheValues = False value = IntCol(alternateID=True) def thr1(): localData = threading.local() localData.conn = connectionForURI(connuri) for i in range(1000): try: a = AAA(value=1,connection=localData.conn) except dberrors.DuplicateEntryError: a = AAA.byValue(1,connection=localData.conn) AAA.dropTable(ifExists=True) AAA.createTable() for i in range(20): t = threading.Thread(target=thr1,args=()) t.start() Here, each thread has its own connection, I ensure the connection object is a local variable (do I really need to do this?) but still the connection gets into a bad state. - nathan ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ sqlobject-discuss mailing list sqlobject-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss