diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sqlalchemy/pool/impl.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/sqlalchemy/pool/impl.py b/lib/sqlalchemy/pool/impl.py index ada319661..e1a457bf3 100644 --- a/lib/sqlalchemy/pool/impl.py +++ b/lib/sqlalchemy/pool/impl.py @@ -13,6 +13,7 @@ import traceback import weakref +from .base import _ConnectionFairy from .base import _ConnectionRecord from .base import Pool from .. import exc @@ -288,6 +289,7 @@ class SingletonThreadPool(Pool): def __init__(self, creator, pool_size=5, **kw): Pool.__init__(self, creator, **kw) self._conn = threading.local() + self._fairy = threading.local() self._all_conns = set() self.size = pool_size @@ -346,6 +348,25 @@ class SingletonThreadPool(Pool): self._all_conns.add(c) return c + def connect(self): + # vendored from Pool to include use_threadlocal behavior + try: + rec = self._fairy.current() + except AttributeError: + pass + else: + if rec is not None: + return rec._checkout_existing() + + return _ConnectionFairy._checkout(self, self._fairy) + + def _return_conn(self, record): + try: + del self._fairy.current + except AttributeError: + pass + self._do_return_conn(record) + class StaticPool(Pool): |
