New submission from John Andersen <johnandersen...@gmail.com>:
aexit called after loop close on death by signal. This seems odd, the __aexit__ method must be running in a loop because it is an async function. However if one calls shield then it dies. ''' $ python3.7 test.py Hello! # Ctrl-C before 5 seconds is up $ python3.7 test.py ^CException ignored in: <coroutine object func at 0x7f0890f08148> Traceback (most recent call last): File "test.py", line 18, in func await asyncio.sleep(5) File "test.py", line 14, in __aexit__ await asyncio.shield(self.other()) File "/usr/lib/python3.7/asyncio/tasks.py", line 765, in shield inner = ensure_future(arg, loop=loop) File "/usr/lib/python3.7/asyncio/tasks.py", line 577, in ensure_future task = loop.create_task(coro_or_future) File "/usr/lib/python3.7/asyncio/base_events.py", line 384, in create_task self._check_closed() File "/usr/lib/python3.7/asyncio/base_events.py", line 461, in _check_closed raise RuntimeError('Event loop is closed') RuntimeError: Event loop is closed sys:1: RuntimeWarning: coroutine 'Test.other' was never awaited ''' import os import signal import asyncio class Test(object): async def other(self): print('Hello!') async def __aenter__(self): pass async def __aexit__(self, a, b, c): await asyncio.shield(self.other()) async def func(): async with Test(): await asyncio.sleep(5) def main(): loop = asyncio.get_event_loop() try: loop.run_until_complete(func()) except KeyboardInterrupt: pass loop.run_until_complete(loop.shutdown_asyncgens()) loop.close() if __name__ == '__main__': main() ---------- components: asyncio messages: 327839 nosy: asvetlov, pdxjohnny, yselivanov priority: normal severity: normal status: open title: aexit called after loop close versions: Python 3.6, Python 3.7, Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue35000> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com