INADA Naoki added the comment: When task.cancel() called, CancelledError is thrown to coro2. But coro2 doesn't call `yield from` after task.cancel(). So the exception is never raised.
If you add `yield from` after `task.cancel()`, the script runs expected. --- $ cat at.py import asyncio as a @a.coroutine def coro1(): yield from a.ensure_future(coro2()) print("Still here") yield from a.sleep(.1) print("Still here 2") @a.coroutine def coro2(): yield from a.sleep(.1) res = task.cancel() print("Canceled task:", res) yield from a.sleep(.1) # !!! added this line loop = a.get_event_loop() task = a.ensure_future(coro1()) loop.run_until_complete(task) $ ./python.exe at.py Canceled task: True Traceback (most recent call last): File "at.py", line 19, in <module> loop.run_until_complete(task) File "/Users/inada-n/work/python/cpython/Lib/asyncio/base_events.py", line 465, in run_until_complete return future.result() concurrent.futures._base.CancelledError ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue30048> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com