From: Mike Bayer Date: Mon, 2 Nov 2020 20:29:38 +0000 (-0500) Subject: Ensure AsyncAdaptedLock is present X-Git-Tag: rel_1_4_0b1~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f21b5ec4ef54a0923311014e4af50f5804fcf49c;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Ensure AsyncAdaptedLock is present whether or not greenlet is installed Change-Id: Icd1c5ef3a01ec0d1b8dce0d1def9920700923e51 --- diff --git a/lib/sqlalchemy/util/_concurrency_py3k.py b/lib/sqlalchemy/util/_concurrency_py3k.py index 82125b7713..ee3abe5fa9 100644 --- a/lib/sqlalchemy/util/_concurrency_py3k.py +++ b/lib/sqlalchemy/util/_concurrency_py3k.py @@ -96,17 +96,6 @@ 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 @@ -119,3 +108,15 @@ except ImportError: # pragma: no cover async def greenlet_spawn(fn, *args, **kw): raise ValueError("Greenlet is required to use this function") + + +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()