diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2022-07-18 22:45:01 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2022-07-18 22:45:01 +0000 |
commit | 42c0928a731954649e95a7ee56b6709b1ec59aed (patch) | |
tree | c66a89d534fb0d4e9ce84393235d3fe7daf184f7 /lib/sqlalchemy/ext/asyncio/session.py | |
parent | f53011e40d7332e28bb6d309db7829ee31c47d7d (diff) | |
parent | 1acaf0b2e4859a274e753b5054dcde3d5c7ca10e (diff) | |
download | sqlalchemy-42c0928a731954649e95a7ee56b6709b1ec59aed.tar.gz |
Merge "add shield() in aexit" into main
Diffstat (limited to 'lib/sqlalchemy/ext/asyncio/session.py')
-rw-r--r-- | lib/sqlalchemy/ext/asyncio/session.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/sqlalchemy/ext/asyncio/session.py b/lib/sqlalchemy/ext/asyncio/session.py index ea587f8de..d4b6b6d50 100644 --- a/lib/sqlalchemy/ext/asyncio/session.py +++ b/lib/sqlalchemy/ext/asyncio/session.py @@ -6,6 +6,7 @@ # the MIT License: https://www.opensource.org/licenses/mit-license.php from __future__ import annotations +import asyncio from typing import Any from typing import Callable from typing import Dict @@ -832,7 +833,7 @@ class AsyncSession(ReversibleProxy[Session]): :meth:`_asyncio.AsyncSession.close` """ - return await greenlet_spawn(self.sync_session.close) + await greenlet_spawn(self.sync_session.close) async def invalidate(self) -> None: """Close this Session, using connection invalidation. @@ -850,7 +851,7 @@ class AsyncSession(ReversibleProxy[Session]): return self async def __aexit__(self, type_: Any, value: Any, traceback: Any) -> None: - await self.close() + await asyncio.shield(self.close()) def _maker_context_manager(self: _AS) -> _AsyncSessionContextManager[_AS]: return _AsyncSessionContextManager(self) @@ -1511,8 +1512,11 @@ class _AsyncSessionContextManager(Generic[_AS]): return self.async_session async def __aexit__(self, type_: Any, value: Any, traceback: Any) -> None: - await self.trans.__aexit__(type_, value, traceback) - await self.async_session.__aexit__(type_, value, traceback) + async def go() -> None: + await self.trans.__aexit__(type_, value, traceback) + await self.async_session.__aexit__(type_, value, traceback) + + await asyncio.shield(go()) class AsyncSessionTransaction( |