Re: [pysqlite] Concurrency - first steps

[email protected] Wed, 19 Nov 2008 00:30:29 -0800
Newsgroups gmane.comp.python.db.pysqlite.user
Message-ID <[email protected]>
On Wed, 5 Nov 2008 21:22:00 +0000, Hugh Gibson wrote:
> Yes, we hit this. I've only recently discovered threading.local giving
> local thread storage which has simplified creating per-thread connections
> (previously had to create a connection in a global structure,
> necessitating a system-wide lock).

Depending on how you use it, threading.local (at least in current
versions of python) can leak references if you use it for storing
objects (like pysqlite Connection objects) whose deallocation may
release the GIL. We ran into this; see http://bugs.python.org/issue3710
and http://bugs.python.org/issue1868 for more discussion.

My *guess* is that if you never rely on python to deallocate the
connection for you -- i.e. before any thread dies, it deletes its
connection out of the threading.local object -- you'll be okay. Or
if you use a constant-sized pool of threads that don't die or get
spawned very often, you may not care about reference leaks anyway.

	~Ben