SystemExit passes through the asyncio loop, so the stop() callback scheduled by the main task's Future's completion doesn't run; which then means it's pending when we re-enter the asyncio loop to do cleanup tasks like shutdown_asyncgens. Fix by not enqueueing the stop() callback if we can tell that the exception is going to pass through the asyncio loop.
SystemExit passes through the asyncio loop, so the
stop()
callback scheduled by the main task's Future's completion doesn't run; which then means it's pending when we re-enter the asyncio loop to do cleanup tasks likeshutdown_asyncgens
. Fix by not enqueueing thestop()
callback if we can tell that the exception is going to pass through the asyncio loop.Relevant upstream issue: https://bugs.python.org/issue22429