diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2020-12-08 18:04:25 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@bbpush.zzzcomputing.com> | 2020-12-08 18:04:25 +0000 |
| commit | c5831b1abd98c46ef7eab7ee82ead18756aea112 (patch) | |
| tree | 4699cf11577807337e92edb197c8a52b4d5969af /lib/sqlalchemy/util | |
| parent | 18b1b261ff988549e75b011f2f4296fb13b24d64 (diff) | |
| parent | 76d90152302461637cfecb6c0cac65a50975c570 (diff) | |
| download | sqlalchemy-c5831b1abd98c46ef7eab7ee82ead18756aea112.tar.gz | |
Merge "Detect non compatible execution in async mode"
Diffstat (limited to 'lib/sqlalchemy/util')
| -rw-r--r-- | lib/sqlalchemy/util/_concurrency_py3k.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/sqlalchemy/util/_concurrency_py3k.py b/lib/sqlalchemy/util/_concurrency_py3k.py index dcee05713..8ad3be543 100644 --- a/lib/sqlalchemy/util/_concurrency_py3k.py +++ b/lib/sqlalchemy/util/_concurrency_py3k.py @@ -79,7 +79,9 @@ def await_fallback(awaitable: Coroutine) -> Any: return current.driver.switch(awaitable) -async def greenlet_spawn(fn: Callable, *args, **kwargs) -> Any: +async def greenlet_spawn( + fn: Callable, *args, _require_await=False, **kwargs +) -> Any: """Runs a sync function ``fn`` in a new greenlet. The sync function can then use :func:`await_` to wait for async @@ -95,9 +97,11 @@ async def greenlet_spawn(fn: Callable, *args, **kwargs) -> Any: # is interrupted by await_, context is not dead and result is a # coroutine to wait. If the context is dead the function has # returned, and its result can be returned. + switch_occurred = False try: result = context.switch(*args, **kwargs) while not context.dead: + switch_occurred = True try: # wait for a coroutine from await_ and then return its # result back to it. @@ -112,6 +116,12 @@ async def greenlet_spawn(fn: Callable, *args, **kwargs) -> Any: finally: # clean up to avoid cycle resolution by gc del context.driver + if _require_await and not switch_occurred: + raise exc.AwaitRequired( + "The current operation required an async execution but none was " + "detected. This will usually happen when using a non compatible " + "DBAPI driver. Please ensure that an async DBAPI is used." + ) return result |
