]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
temporary workaround dispose_local() added to SingletonThreadPool
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 5 Aug 2006 15:11:52 +0000 (15:11 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 5 Aug 2006 15:11:52 +0000 (15:11 +0000)
for sqlite applications that dispose of threads en masse

CHANGES
doc/build/content/pooling.txt
lib/sqlalchemy/pool.py

diff --git a/CHANGES b/CHANGES
index ddc0a6f0c1053c2f55ea381f9c96ebaf5a777528..ff2fe439307399f9f2a57ac8355bb294bfb67e40 100644 (file)
--- 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
index 1334a04d1ec754249c7d16b58fbd3409e53d23d3..e364733b1c08fd0349d4a770505b399ea482659f 100644 (file)
@@ -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
index d71f645a6e72f06438b3170a2875d335b055711b..dd27755c54460120b6197c173e3c3d851feafdaa 100644 (file)
@@ -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))