diff options
author | Federico Caselli <cfederico87@gmail.com> | 2022-09-13 21:23:12 +0200 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-09-15 09:02:33 -0400 |
commit | 939f77c94b4e47ea611672a85047b61ab7e3590b (patch) | |
tree | 4bd1f2e6b1a8da8588d783a16b58333e41cd9547 /lib/sqlalchemy/ext/asyncio/session.py | |
parent | de173b600b0d3747bcf1941e3027598c66da33ac (diff) | |
download | sqlalchemy-939f77c94b4e47ea611672a85047b61ab7e3590b.tar.gz |
Improved usage of ``asyncio.shield()``
Fixes: #8516
Change-Id: Ifd8f5e5f42d9fbcd5b8d00bddc81ff6be690a75e
Diffstat (limited to 'lib/sqlalchemy/ext/asyncio/session.py')
-rw-r--r-- | lib/sqlalchemy/ext/asyncio/session.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/sqlalchemy/ext/asyncio/session.py b/lib/sqlalchemy/ext/asyncio/session.py index d4b6b6d50..60b77f3ea 100644 --- a/lib/sqlalchemy/ext/asyncio/session.py +++ b/lib/sqlalchemy/ext/asyncio/session.py @@ -851,7 +851,8 @@ class AsyncSession(ReversibleProxy[Session]): return self async def __aexit__(self, type_: Any, value: Any, traceback: Any) -> None: - await asyncio.shield(self.close()) + task = asyncio.create_task(self.close()) + await asyncio.shield(task) def _maker_context_manager(self: _AS) -> _AsyncSessionContextManager[_AS]: return _AsyncSessionContextManager(self) @@ -1516,7 +1517,8 @@ class _AsyncSessionContextManager(Generic[_AS]): await self.trans.__aexit__(type_, value, traceback) await self.async_session.__aexit__(type_, value, traceback) - await asyncio.shield(go()) + task = asyncio.create_task(go()) + await asyncio.shield(task) class AsyncSessionTransaction( |