MySQLdb multithreaded

Skip Montanaro skip at pobox.com
Wed May 7 13:17:18 EDT 2003


    Bram> MySQLdb package claims thread-safety.  I am doing a lot of
    Bram> multithreaded queries, which give me crashes.  single thread is
    Bram> OK.

    Bram> Can I have multiple threads use the same connection to the db, or
    Bram> does each thread require its own connection?

Yes, but the connections can't be shared by multiple threads concurrently
(level 1, not level 2 concurrency I think, I forget the exact terminology
and numbers).  I hold several connections in a Queue.Queue() instance, pull
one out when a thread needs one, put it back when finished.  Works like a
charm.  The number of connections you place in the queue help to easily
limit the load on your database server as well.

Skip





More information about the Python-list mailing list