--- /dev/null
+.. change::
+ :tags: bug, asyncio
+ :tickets: 8516
+
+ Improved implementation of ``asyncio.shield()`` used in context managers as
+ added in :ticket:`8145`, such that the "close" operation is enclosed within
+ an ``asyncio.Task`` which is then strongly referenced as the operation
+ proceeds. This is per Python documentation indicating that the task is
+ otherwise not strongly referenced.
return self.start().__await__()
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)
# START PROXY METHODS AsyncConnection
await self.transaction.__aexit__(type_, value, traceback)
await self.conn.close()
- await asyncio.shield(go())
+ task = asyncio.create_task(go())
+ await asyncio.shield(task)
def __init__(self, sync_engine: Engine):
if not sync_engine.dialect.is_async:
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)
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(