diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-08-23 09:28:06 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-08-24 13:02:23 -0400 |
commit | 776abf43d7404a3fa165588fd1e1e2d5ef9a9f04 (patch) | |
tree | 135f6055d98c0a956f32378d53d6ea6c6a358ad9 /lib/sqlalchemy/engine/interfaces.py | |
parent | 27bf1c1c287debb69c4644bf6dc35e3bad5470ad (diff) | |
download | sqlalchemy-776abf43d7404a3fa165588fd1e1e2d5ef9a9f04.tar.gz |
integrate connection.terminate() for supporting dialects
Integrated support for asyncpg's ``terminate()`` method call for cases
where the connection pool is recycling a possibly timed-out connection,
where a connection is being garbage collected that wasn't gracefully
closed, as well as when the connection has been invalidated. This allows
asyncpg to abandon the connection without waiting for a response that may
incur long timeouts.
Fixes: #8419
Change-Id: Ia575af779d5733b483a72dff3690b8bbbad2bb05
Diffstat (limited to 'lib/sqlalchemy/engine/interfaces.py')
-rw-r--r-- | lib/sqlalchemy/engine/interfaces.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/sqlalchemy/engine/interfaces.py b/lib/sqlalchemy/engine/interfaces.py index 778c07592..01b266d68 100644 --- a/lib/sqlalchemy/engine/interfaces.py +++ b/lib/sqlalchemy/engine/interfaces.py @@ -966,6 +966,10 @@ class Dialect(EventTarget): is_async: bool """Whether or not this dialect is intended for asyncio use.""" + has_terminate: bool + """Whether or not this dialect has a separate "terminate" implementation + that does not block or require awaiting.""" + engine_config_types: Mapping[str, Any] """a mapping of string keys that can be in an engine config linked to type conversion functions. @@ -1784,6 +1788,23 @@ class Dialect(EventTarget): raise NotImplementedError() + def do_terminate(self, dbapi_connection: DBAPIConnection) -> None: + """Provide an implementation of ``connection.close()`` that tries as + much as possible to not block, given a DBAPI + connection. + + In the vast majority of cases this just calls .close(), however + for some asyncio dialects may call upon different API features. + + This hook is called by the :class:`_pool.Pool` + when a connection is being recycled or has been invalidated. + + .. versionadded:: 1.4.41 + + """ + + raise NotImplementedError() + def do_close(self, dbapi_connection: DBAPIConnection) -> None: """Provide an implementation of ``connection.close()``, given a DBAPI connection. |