mysqldb + multi-threading
Bryan Olson
fakeaddress at nowhere.org
Fri Sep 8 19:09:18 EDT 2006
skip at pobox.com wrote:
> Bryan> MySQL has its own process. It doesn't know nor care whether your
> Bryan> application makes connections from different processes or
> Bryan> different threads in the same process.
>
> Yes, but on the client side the data structures may or may not be
> thread-safe.
I was responding to the text I quoted immediately above it:
"I saw in another thread that some db engines did have issues
with being called from threads." He is right about that, but
it's not a problem given what he said he's using.
> A session on my web server:
>
> [skip at orca ~]$ python
> Python 2.3.4 (#1, Mar 10 2006, 06:12:09)
> [GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import MySQLdb
> >>> MySQLdb.threadsafety
> 1
> >>> MySQLdb.version_info
> (1, 1, 7, 'final', 1)
>
> Looking up threadsafety in PEP 249 we see:
>
> threadsafety
>
> Integer constant stating the level of thread safety the
> interface supports. Possible values are:
>
> 0 Threads may not share the module.
> 1 Threads may share the module, but not connections.
> 2 Threads may share the module and connections.
> 3 Threads may share the module, connections and
> cursors.
>
> So if you want to use multiple threads they can't share connections.
I don't see how multiple processes could share connections
either.
> >> My gut feeling is to use threads (note: each transaction is finite,
> >> so the process/thread die fairly quickly).
>
> Bryan> Go with your gut. Python threads are reasonably portable, and
> Bryan> work well on modern MS-Windows.
>
> Maybe ignore your gut and read the documentation. ;-)
What in the documentation do you think answers the question?
--
--Bryan
More information about the Python-list
mailing list