INADA Naoki added the comment:
> The problem is that the task doesn't catch CancelledError, yet it disappears.
The problem is CancelledError is not raised, even it's thrown.
Task can't catch exception not raised. See below example which demonstrates
how task works.
---
from asyncio import CancelledError
cancelled = False
def coro():
global cancelled
print(1)
yield (1,)
print("cancel")
cancelled = True
#print(2)
#yield (2,) # uncomment this line makes cancel success.
c = coro()
while True:
try:
if cancelled:
r = c.throw(CancelledError)
else:
r = c.send(None)
except StopIteration:
print("end")
break
except CancelledError:
print("cancelled")
break
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue30048>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com