python-trio / trio-asyncio

a re-implementation of the asyncio mainloop on top of Trio
Other
187 stars 37 forks source link

Fix spurious error when asyncio.run() task raises SystemExit #149

Closed oremanj closed 2 months ago

oremanj commented 2 months ago

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.

Relevant upstream issue: https://bugs.python.org/issue22429