summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/util/_concurrency_py3k.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-06-07 11:28:49 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-06-07 12:44:58 -0400
commit2fa39312b2c878b717d4c4f41380e5a8931eb374 (patch)
treeb9b33cf021e82227bd6ab237a06922e0388769be /lib/sqlalchemy/util/_concurrency_py3k.py
parent94169108cdd4dace09b752a6af4f4404819b49a3 (diff)
downloadsqlalchemy-2fa39312b2c878b717d4c4f41380e5a8931eb374.tar.gz
Add asyncio.TimeoutError as an exit exception
Added ``asyncio.exceptions.TimeoutError``, ``asyncio.exceptions.CancelledError`` as so-called "exit exceptions", a class of exceptions that include things like ``GreenletExit`` and ``KeyboardInterrupt``, which are considered to be events that warrant considering a DBAPI connection to be in an unusable state where it should be recycled. Fixes: #6592 Change-Id: Idcfa7aaa2d7660838b907388db9c6457afa6edbd
Diffstat (limited to 'lib/sqlalchemy/util/_concurrency_py3k.py')
-rw-r--r--lib/sqlalchemy/util/_concurrency_py3k.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/sqlalchemy/util/_concurrency_py3k.py b/lib/sqlalchemy/util/_concurrency_py3k.py
index 3b60e6584..88294557d 100644
--- a/lib/sqlalchemy/util/_concurrency_py3k.py
+++ b/lib/sqlalchemy/util/_concurrency_py3k.py
@@ -10,7 +10,6 @@ from . import compat
from .langhelpers import memoized_property
from .. import exc
-
if compat.py37:
try:
from contextvars import copy_context as _copy_context
@@ -25,6 +24,12 @@ else:
_copy_context = None
+def is_exit_exception(e):
+ return not isinstance(e, Exception) or isinstance(
+ e, (asyncio.TimeoutError, asyncio.CancelledError)
+ )
+
+
# implementation based on snaury gist at
# https://gist.github.com/snaury/202bf4f22c41ca34e56297bae5f33fef
# Issue for context: https://github.com/python-greenlet/greenlet/issues/173