◐ Shell
clean mode source ↗

bpo-39010: Ignore error on cancelled future after end of loop. by cmeyer · Pull Request #20525 · python/cpython

Python 3.8+ outputs spurious error messages for any asyncio.run_forever call with pending run_in_executor calls when it finishes. When used in a loop that single steps through asyncio using loop.stop() followed by loop.run_forever(), there are repeated, useless error messages. The spurious error messages cannot be prevented in any way I can find.

This patch prevents these spurious error messages. The proactor and windows event code probably needs broader improvements to manage its state properly at exit. This patch does not deal with the broader issue. This patch is only a stop-gap to make Python 3.8 usable by our users.

The bug is easily reproduced with the following code (Windows only). I could not make a test case which would fail on the error since the exception is handled (and output) in low level code.

import asyncio
loop = asyncio.get_event_loop()
f = loop.run_in_executor(None, lambda: None)
loop.stop()
loop.run_forever()
loop.stop()
loop.run_forever()
loop.stop()
loop.run_forever()

https://bugs.python.org/issue39010