Message291528
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 |
|
Date |
User |
Action |
Args |
2017-04-12 08:18:02 | methane | set | recipients:
+ methane, abacabadabacaba, yselivanov |
2017-04-12 08:18:02 | methane | set | messageid: <1491985082.51.0.591586853825.issue30048@psf.upfronthosting.co.za> |
2017-04-12 08:18:02 | methane | link | issue30048 messages |
2017-04-12 08:18:02 | methane | create | |
|