From: Mike Bayer Date: Sat, 5 Aug 2006 15:11:52 +0000 (+0000) Subject: temporary workaround dispose_local() added to SingletonThreadPool X-Git-Tag: rel_0_2_7~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d95e9daec3d44bd8d5725cf0b48cd583f8c2954;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git temporary workaround dispose_local() added to SingletonThreadPool for sqlite applications that dispose of threads en masse --- diff --git a/CHANGES b/CHANGES index ddc0a6f0c1..ff2fe43930 100644 --- a/CHANGES +++ b/CHANGES @@ -19,6 +19,8 @@ overflow counter should only be decremented if the connection actually succeeded. added a test script to attempt testing this. - fixed mysql reflection of default values to be PassiveDefault - added reflected 'tinyint' type to MS-SQL [ticket:263] +- temporary workaround dispose_local() added to SingletonThreadPool +for sqlite applications that dispose of threads en masse 0.2.6 - big overhaul to schema to allow truly composite primary and foreign diff --git a/doc/build/content/pooling.txt b/doc/build/content/pooling.txt index 1334a04d1e..e364733b1c 100644 --- a/doc/build/content/pooling.txt +++ b/doc/build/content/pooling.txt @@ -67,3 +67,16 @@ Or with SingletonThreadPool: # SQLite connections require the SingletonThreadPool p = pool.SingletonThreadPool(getconn) +#### Important Note about Disposing Threads with SingletonThreadPool {@name=note} + +SQLite connections automatically use `SingletonThreadPool` to manage connections. This is a simple dictionary of connections mapped to the identifiers of threads. If you are running an application which disposes of threads, such as FastCGI or SimpleHTTPServer, it is *extremely important* that the corresponding SQLite connection within the exiting thread also be removed, or the connection will remain: + + {python} + pool.dispose_local() + +Or with an engine: + + {python} + engine.connection_provider._pool.dispose_local() + +A future release of SQLAlchemy will address this in a more automated way. \ No newline at end of file diff --git a/lib/sqlalchemy/pool.py b/lib/sqlalchemy/pool.py index d71f645a6e..dd27755c54 100644 --- a/lib/sqlalchemy/pool.py +++ b/lib/sqlalchemy/pool.py @@ -197,7 +197,13 @@ class SingletonThreadPool(Pool): # sqlite won't even let you close a conn from a thread that didn't create it pass del self._conns[key] - + + def dispose_local(self): + try: + del self._conns[thread.get_ident()] + except KeyError: + pass + def status(self): return "SingletonThreadPool id:%d thread:%d size: %d" % (id(self), thread.get_ident(), len(self._conns))