Hi List,
I use asyncio to start several tasks with asyncio.async. Several
of them need to close some things before exiting, so I use
a try...finally construction to do that. Unfortunately, the
finalizers are never called.
When running the event loop, I am using the same code as in
several examples in the docs:
try:
loop.run_forever()
finally:
loop.close()
The documentation for BaseEventLoop.close says that it "clears the queues".
Going through the code I realized that it is doing exactly just that.
I do think it should actually do more, namely it should close the running
tasks (i.e. raise a CancelledError in the coroutines). Otherwise there is
not
much sense to have this close method at all, the garbage collector is good
enough to deal with clearing queues.
Now one might argue that the behavior shouldn't change anymore, but
maybe we can add a new method, e.g. BaseEventLoop.cancel(),
which cancels all running coroutines.
Greetings
Martin