diff options
Diffstat (limited to 'lib/sqlalchemy/ext/asyncio')
-rw-r--r-- | lib/sqlalchemy/ext/asyncio/engine.py | 12 | ||||
-rw-r--r-- | lib/sqlalchemy/ext/asyncio/session.py | 12 |
2 files changed, 16 insertions, 8 deletions
diff --git a/lib/sqlalchemy/ext/asyncio/engine.py b/lib/sqlalchemy/ext/asyncio/engine.py index 2418dab88..e8ac10a3d 100644 --- a/lib/sqlalchemy/ext/asyncio/engine.py +++ b/lib/sqlalchemy/ext/asyncio/engine.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 @@ -693,7 +694,7 @@ class AsyncConnection( return self.start().__await__() async def __aexit__(self, type_: Any, value: Any, traceback: Any) -> None: - await self.close() + await asyncio.shield(self.close()) # START PROXY METHODS AsyncConnection @@ -855,8 +856,11 @@ class AsyncEngine(ProxyComparable[Engine], AsyncConnectable): async def __aexit__( self, type_: Any, value: Any, traceback: Any ) -> None: - await self.transaction.__aexit__(type_, value, traceback) - await self.conn.close() + async def go() -> None: + await self.transaction.__aexit__(type_, value, traceback) + await self.conn.close() + + await asyncio.shield(go()) def __init__(self, sync_engine: Engine): if not sync_engine.dialect.is_async: @@ -956,7 +960,7 @@ class AsyncEngine(ProxyComparable[Engine], AsyncConnectable): """ - return await greenlet_spawn(self.sync_engine.dispose, close=close) + await greenlet_spawn(self.sync_engine.dispose, close=close) # START PROXY METHODS AsyncEngine 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( |