Hi,
While I tried to write a example cancelling create_connection(), I saw
that asynico.wait() doesn't cancel waited tasks when it is cancelled.
In the following example, the result of fut is never used, so asyncio
emits a warning (exception never retrieved):
---
import asyncio
def func():
fut = asyncio.Future()
fs = [fut]
fut2 = loop.create_task(asyncio.wait(fs))
fut2.cancel()
fut.set_exception(ValueError("never catched"))
try:
yield from fut2
except asyncio.CancelledError:
pass
# nobody cares of fut result?
loop = asyncio.get_event_loop()
loop.run_until_complete(func())
loop.close()
---
Is it correct that wait() doesn't cancel waited tasks?
wait_for() was modified recently to cancel the waited task when
wait_for() is cancelled:
http://bugs.python.org/issue23219
asyncio.gather() does cancel tasks when it is cancelled:
https://docs.python.org/dev/library/asyncio-task.html#asyncio.gather
If wait() must not cancel tasks, it should be better explained in the
documentation and asyncio code should be audited to ensure that tasks
are explicitly cancelled.
For example, replace:
yield from tasks.wait(fs, loop=self)
with:
try:
yield from tasks.wait(fs, loop=self)
except CancelledError:
for fut in fs:
fut.cancel()
I only found one method calling wait(): create_connection().
Victor