diff options
-rw-r--r-- | lib/sqlalchemy/databases/sqlite.py | 4 | ||||
-rw-r--r-- | lib/sqlalchemy/pool.py | 17 | ||||
-rw-r--r-- | test/engine/proxy_engine.py | 9 |
3 files changed, 22 insertions, 8 deletions
diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py index b2aeb75fd..d96c0eda1 100644 --- a/lib/sqlalchemy/databases/sqlite.py +++ b/lib/sqlalchemy/databases/sqlite.py @@ -154,6 +154,10 @@ class SQLiteDialect(ansisql.ANSIDialect): def has_table(self, connection, table_name): cursor = connection.execute("PRAGMA table_info(" + table_name + ")", {}) row = cursor.fetchone() + + # consume remaining rows, to work around: http://www.sqlite.org/cvstrac/tktview?tn=1884 + while cursor.fetchone() is not None:pass + return (row is not None) def reflecttable(self, connection, table): diff --git a/lib/sqlalchemy/pool.py b/lib/sqlalchemy/pool.py index 9aa149d5e..7a88ac6f7 100644 --- a/lib/sqlalchemy/pool.py +++ b/lib/sqlalchemy/pool.py @@ -124,6 +124,12 @@ class Pool(object): def log(self, msg): self._logger.write(msg) + def dispose(self): + raise NotImplementedError() + + def __del__(self): + self.dispose() + class ConnectionFairy(object): def __init__(self, pool, connection=None): self.pool = pool @@ -184,7 +190,14 @@ class SingletonThreadPool(Pool): self._creator = creator def dispose(self): - pass + for key, conn in self._conns.items(): + try: + conn.close() + except: + # sqlite won't even let you close a conn from a thread that didn't create it + pass + del self._conns[key] + def status(self): return "SingletonThreadPool id:%d thread:%d size: %d" % (id(self), thread.get_ident(), len(self._conns)) @@ -241,8 +254,6 @@ class QueuePool(Pool): conn.close() except Queue.Empty: break - def __del__(self): - self.dispose() def status(self): tup = (self.size(), self.checkedin(), self.overflow(), self.checkedout()) diff --git a/test/engine/proxy_engine.py b/test/engine/proxy_engine.py index d468e946f..5b957b4dc 100644 --- a/test/engine/proxy_engine.py +++ b/test/engine/proxy_engine.py @@ -123,6 +123,7 @@ class ThreadProxyTest(ProxyTestBase): assert names == [uname] finally: module_metadata.drop_all(module_engine) + module_engine.get_engine().dispose() except Exception, e: import traceback traceback.print_exc() @@ -131,20 +132,18 @@ class ThreadProxyTest(ProxyTestBase): queue.put(False) return test - # NOTE: I'm not sure how to give the test runner the option to - # override these uris, or how to safely clear them after test runs a = Thread(target=run('sqlite:///threadtesta.db', 'jim', qa)) b = Thread(target=run('sqlite:///threadtestb.db', 'joe', qb)) a.start() b.start() - + # block and wait for the threads to push their results - res = qa.get(True) + res = qa.get() if res != False: raise res - res = qb.get(True) + res = qb.get() if res != False: raise res |