diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-09-14 08:04:09 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-09-14 08:04:09 -0400 |
| commit | 4d17fe4063adef50c1d529993e0b047f503940e2 (patch) | |
| tree | 20b53461c593e71297fa034ccdaaea629c461728 /lib/sqlalchemy/util | |
| parent | 056c929e15c735059b2f17f9ae5391d3ad244907 (diff) | |
| download | sqlalchemy-4d17fe4063adef50c1d529993e0b047f503940e2.tar.gz | |
Adapt event exec_once_mutex to asyncio
The pool makes use of a threading.Lock() for the
"first_connect" event. if the pool is async make sure this
is a greenlet-adapted asyncio lock.
Fixes: #5581
Change-Id: If52415839c7ed82135465f1fe93b95d86c305820
Diffstat (limited to 'lib/sqlalchemy/util')
| -rw-r--r-- | lib/sqlalchemy/util/_concurrency_py3k.py | 11 | ||||
| -rw-r--r-- | lib/sqlalchemy/util/concurrency.py | 4 |
2 files changed, 15 insertions, 0 deletions
diff --git a/lib/sqlalchemy/util/_concurrency_py3k.py b/lib/sqlalchemy/util/_concurrency_py3k.py index 3b112ff7d..82125b771 100644 --- a/lib/sqlalchemy/util/_concurrency_py3k.py +++ b/lib/sqlalchemy/util/_concurrency_py3k.py @@ -96,6 +96,17 @@ try: del context.driver return result + class AsyncAdaptedLock: + def __init__(self): + self.mutex = asyncio.Lock() + + def __enter__(self): + await_fallback(self.mutex.acquire()) + return self + + def __exit__(self, *arg, **kw): + self.mutex.release() + except ImportError: # pragma: no cover greenlet = None diff --git a/lib/sqlalchemy/util/concurrency.py b/lib/sqlalchemy/util/concurrency.py index 4c4ea20d1..e0883aa68 100644 --- a/lib/sqlalchemy/util/concurrency.py +++ b/lib/sqlalchemy/util/concurrency.py @@ -7,6 +7,7 @@ if compat.py3k: from ._concurrency_py3k import await_fallback from ._concurrency_py3k import greenlet from ._concurrency_py3k import greenlet_spawn + from ._concurrency_py3k import AsyncAdaptedLock else: asyncio = None greenlet = None @@ -19,3 +20,6 @@ else: def greenlet_spawn(fn, *args, **kw): raise ValueError("Cannot use this function in py2.") + + def AsyncAdaptedLock(*args, **kw): + raise ValueError("Cannot use this function in py2.") |
