This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author methane
Recipients abacabadabacaba, methane, yselivanov
Date 2017-04-12.08:18:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1491985082.51.0.591586853825.issue30048@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2017-04-12 08:18:02methanesetrecipients: + methane, abacabadabacaba, yselivanov
2017-04-12 08:18:02methanesetmessageid: <1491985082.51.0.591586853825.issue30048@psf.upfronthosting.co.za>
2017-04-12 08:18:02methanelinkissue30048 messages
2017-04-12 08:18:02methanecreate