summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES2
-rw-r--r--doc/build/content/pooling.txt13
-rw-r--r--lib/sqlalchemy/pool.py8
3 files changed, 22 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index ddc0a6f0c..ff2fe4393 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 1334a04d1..e364733b1 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 d71f645a6..dd27755c5 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))