[Sqlalchemy-tickets] Issue #3376: SingletonThreadPool and threading.local() usage (zzzeek/sqlalchem
Brought to you by:
zzzeek
|
From: André A. <iss...@bi...> - 2015-04-21 10:56:30
|
New issue 3376: SingletonThreadPool and threading.local() usage https://bitbucket.org/zzzeek/sqlalchemy/issue/3376/singletonthreadpool-and-threadinglocal André Anjos: I'm a bit puzzled by the SingletonThreadPool implementation. As per recommendation (see discussion on [this StackOverflow thread](http://stackoverflow.com/questions/1408171/thread-local-storage-in-python)), the call to `threading.local()` must be global, whereas in `sqlalchemy.pool`, it is rather local, at the constructor of the `SingletonThreadPool` object. As a result, If many sessions are attempted to the database on the same process, the constructor of the SingletonThreadPool object will be triggered many times and a fake perception that the singleton does not exist will kick-in and trigger the re-construction of a connection. After sometime, we start getting spurious messages: ``` Exception during reset or similar Traceback (most recent call last): File "/idiap/project/beat/beat.env.develop/usr/lib/python2.7/site-packages/sqlalchemy/pool.py", line 568, in _finalize_fairy fairy._reset(pool) File "/idiap/project/beat/beat.env.develop/usr/lib/python2.7/site-packages/sqlalchemy/pool.py", line 702, in _reset pool._dialect.do_rollback(self) File "/idiap/project/beat/beat.env.develop/usr/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 412, in do_rollback dbapi_connection.rollback() ProgrammingError: Cannot operate on a closed database. ``` We wonder if this is not the cause. Could somebody verify this please? |