summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/pool.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2005-11-06 20:17:13 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2005-11-06 20:17:13 +0000
commitac101149089e573add3dc65ac783547b711f20ed (patch)
treeb5a8d361a6978458252f6c0fa69cebf9ee040886 /lib/sqlalchemy/pool.py
parent415ee39db578a17cefc1e4ccd8526ec5612be2e0 (diff)
downloadsqlalchemy-ac101149089e573add3dc65ac783547b711f20ed.tar.gz
sqlite cant share among threads ! hence a new pool class.
Diffstat (limited to 'lib/sqlalchemy/pool.py')
-rw-r--r--lib/sqlalchemy/pool.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/sqlalchemy/pool.py b/lib/sqlalchemy/pool.py
index 53e861393..fc1e3c502 100644
--- a/lib/sqlalchemy/pool.py
+++ b/lib/sqlalchemy/pool.py
@@ -111,8 +111,26 @@ class CursorFairy(object):
self.cursor = cursor
def __getattr__(self, key):
return getattr(self.cursor, key)
+
+class SingletonThreadPool(Pool):
+ """Maintains one connection per each thread, never moving to another thread. this is used for SQLite and other databases with a similar restriction."""
+ def __init__(self, creator, **params):
+ params['use_threadlocal'] = False
+ Pool.__init__(self, **params)
+ self._conns = {}
+ self._creator = creator
+
+ def return_conn(self, conn):
+ pass
+ def get(self):
+ try:
+ return self._conns[thread.get_ident()]
+ except KeyError:
+ return self._conns.setdefault(thread.get_ident(), self._creator())
+
class QueuePool(Pool):
+ """uses Queue.Queue to maintain a fixed-size list of connections."""
def __init__(self, creator, pool_size = 5, max_overflow = 10, **params):
Pool.__init__(self, **params)
self._creator = creator