This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pdxjohnny
Recipients asvetlov, pdxjohnny, yselivanov
Date 2018-10-16.15:49:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1539704951.84.0.788709270274.issue35000@psf.upfronthosting.co.za>
In-reply-to
Content
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()
History
Date User Action Args
2018-10-16 15:49:11pdxjohnnysetrecipients: + pdxjohnny, asvetlov, yselivanov
2018-10-16 15:49:11pdxjohnnysetmessageid: <1539704951.84.0.788709270274.issue35000@psf.upfronthosting.co.za>
2018-10-16 15:49:11pdxjohnnylinkissue35000 messages
2018-10-16 15:49:11pdxjohnnycreate