If I ran this in the python3 interpreter:
import asyncio @asyncio.coroutine def wait(n): asyncio.sleep(n) loop = asyncio.get_event_loop() fut = asyncio.async(wait(10)) fut.add_done_callback(lambda x: print('Done')) asyncio.Task.all_tasks()
I get the following result:
{<Task pending coro=<coro() running at /usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/coroutines.py:139> cb=[<lambda>() at <ipython-input-5-c72c2da2ffa4>:1]>}
Now, if I run fut.cancel() , I return True . But typing fut returns a view of the task that it cancels:
<Task cancelling coro=<coro() running at /usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/coroutines.py:139> cb=[<lambda>() at <ipython-input-5-c72c2da2ffa4>:1]>
And the task is never canceled ( fut.cancelled() never returns True )
Why doesn't he cancel?
source share