summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/util/_concurrency_py3k.py
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2021-04-30 22:36:59 +0200
committerMike Bayer <mike_mp@zzzcomputing.com>2021-05-01 11:58:13 -0400
commitfc7a3533417d970e47397f4da874e5e73e9f1c72 (patch)
treefb7b645ed4b7b2f72f2f2c273694c1631d577b0a /lib/sqlalchemy/util/_concurrency_py3k.py
parenta47c158a9a3b1104698fc0bff47ca58d67cb9191 (diff)
downloadsqlalchemy-fc7a3533417d970e47397f4da874e5e73e9f1c72.tar.gz
Avoid creating asyncio.Lock on the wrong loop.
Fixed a regression introduced by :ticket:`6337` that would create an ``asyncio.Lock`` which could be attached to the wrong loop when instantiating the async engine before any asyncio loop was started, leading to an asyncio error message when attempting to use the engine under certain circumstances. Fixes: #6409 Change-Id: I8119c56b44a7bd70a650c0ea676892d4d7814a8b
Diffstat (limited to 'lib/sqlalchemy/util/_concurrency_py3k.py')
-rw-r--r--lib/sqlalchemy/util/_concurrency_py3k.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/sqlalchemy/util/_concurrency_py3k.py b/lib/sqlalchemy/util/_concurrency_py3k.py
index b905f903b..5f03972b2 100644
--- a/lib/sqlalchemy/util/_concurrency_py3k.py
+++ b/lib/sqlalchemy/util/_concurrency_py3k.py
@@ -7,6 +7,7 @@ from typing import Coroutine
import greenlet
from . import compat
+from .langhelpers import memoized_property
from .. import exc
@@ -132,10 +133,15 @@ async def greenlet_spawn(
class AsyncAdaptedLock:
- def __init__(self):
- self.mutex = asyncio.Lock()
+ @memoized_property
+ def mutex(self):
+ # there should not be a race here for coroutines creating the
+ # new lock as we are not using await, so therefore no concurrency
+ return asyncio.Lock()
def __enter__(self):
+ # await is used to acquire the lock only after the first calling
+ # coroutine has created the mutex.
await_fallback(self.mutex.acquire())
return self