]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
sqlite cant share among threads ! hence a new pool class.
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 6 Nov 2005 20:17:13 +0000 (20:17 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 6 Nov 2005 20:17:13 +0000 (20:17 +0000)
lib/sqlalchemy/databases/sqlite.py
lib/sqlalchemy/pool.py

index da993d9a520951bbb8b49bc968d5e72a763c39bc..53c5b771f54fed85a42b751ea6ec7e38f09814b6 100644 (file)
@@ -87,6 +87,7 @@ class SQLiteSQLEngine(ansisql.ANSISQLEngine):
     def __init__(self, opts, **params):
         self.filename = opts.pop('filename')
         self.opts = opts or {}
+        params['poolclass'] = sqlalchemy.pool.SingletonThreadPool
         ansisql.ANSISQLEngine.__init__(self, **params)
 
     def post_exec(self, connection, cursor, statement, parameters, echo = None, compiled = None, **kwargs):
index 53e861393bdc314bd00bb27560251b2d26339d25..fc1e3c502a973b8ebfac56adf8377cab567c8956 100644 (file)
@@ -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