]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add asyncio.TimeoutError as an exit exception
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 7 Jun 2021 15:28:49 +0000 (11:28 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 7 Jun 2021 16:44:58 +0000 (12:44 -0400)
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

doc/build/changelog/unreleased_14/6592.rst [new file with mode: 0644]
lib/sqlalchemy/engine/base.py
lib/sqlalchemy/util/__init__.py
lib/sqlalchemy/util/_concurrency_py3k.py
lib/sqlalchemy/util/concurrency.py

diff --git a/doc/build/changelog/unreleased_14/6592.rst b/doc/build/changelog/unreleased_14/6592.rst
new file mode 100644 (file)
index 0000000..896789b
--- /dev/null
@@ -0,0 +1,10 @@
+.. change::
+    :tags: bug, asyncio
+    :tickets: 6592
+
+    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.
index 663482b1f5a1962b3eee5dc29fb414cb41e1eb6c..64f638a50d0210a68e9a757a3a601527ceb8fc76 100644 (file)
@@ -1877,7 +1877,7 @@ class Connection(Connectable):
     ):
         exc_info = sys.exc_info()
 
-        is_exit_exception = not isinstance(e, Exception)
+        is_exit_exception = util.is_exit_exception(e)
 
         if not self._is_disconnect:
             self._is_disconnect = (
@@ -2325,7 +2325,6 @@ class Transaction(TransactionalContext):
           phase transactions may be used.
 
         """
-
         try:
             self._do_commit()
         finally:
index 89d09f930fa76b0b9f87dfb994b0b9ee8044c36c..db3966849846ced77151d51cfe600121d48ce69d 100644 (file)
@@ -101,6 +101,7 @@ from .concurrency import asyncio
 from .concurrency import await_fallback
 from .concurrency import await_only
 from .concurrency import greenlet_spawn
+from .concurrency import is_exit_exception
 from .deprecations import deprecated
 from .deprecations import deprecated_20
 from .deprecations import deprecated_20_cls
index 3b60e6584a0527f8ea1e360fd13ca3ff2836d144..88294557d7c0a74225be5c6665a845a7602124c7 100644 (file)
@@ -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
index 60db9cfff534d11a80bcaa7006f7fe8177d64d12..4635473191fe8cb25b16bc2ce7695c7719761792 100644 (file)
@@ -12,6 +12,7 @@ if compat.py3k:
         from ._concurrency_py3k import await_only
         from ._concurrency_py3k import await_fallback
         from ._concurrency_py3k import greenlet_spawn
+        from ._concurrency_py3k import is_exit_exception
         from ._concurrency_py3k import AsyncAdaptedLock
         from ._concurrency_py3k import _util_async_run  # noqa F401
         from ._concurrency_py3k import (
@@ -36,6 +37,9 @@ if not have_greenlet:
                 "the greenlet library is required to use this function."
             )
 
+    def is_exit_exception(e):  # noqa F811
+        return not isinstance(e, Exception)
+
     def await_only(thing):  # noqa F811
         _not_implemented()