Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does an "Executing <Handle <TaskWakeupMethWrapper..." warning in python asyncio mean

The message below is being printed while setting the result of an asyncio future.

Executing <Handle <TaskWakeupMethWrapper object at 0x7fc3435141f8>(<Future finis...ection.py:260>) created at /media/stuff/stuff/projects/dare/dcds/dcds/common/connection.py:221> took 1.723 seconds

I have no idea where even to start looking for the cause. But if I turn off the asyncio debug mode it crashes and shows me this.

Task was destroyed but it is pending!
task: <Task pending coro=<upload.<locals>.upload_coro() done, defined at /media/stuff/stuff/projects/dare/dcds/dcds/__main__.py:58> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7fdf5df01d38>()]> cb=[_chain_future.<locals>._call_set_state() at /home/elviento/anaconda3/lib/python3.6/asyncio/futures.py:414]>
like image 397
Aaron de Windt Avatar asked Nov 24 '17 15:11

Aaron de Windt


2 Answers

In recent versions* of Python, you will get a bit more information on which task is holding the event loop for too long. The feature is discussed more here: https://bugs.python.org/issue38986

* Python 3.7.6 or Python 3.8.1

like image 198
carver Avatar answered Oct 15 '22 03:10

carver


Executing <Handle <TaskWakeupMethWrapper object at 0x7fc3435141f8>(<Future finis...ection.py:260>) created at /media/stuff/stuff/projects/dare/dcds/dcds/common/connection.py:221> took 1.723 seconds

Main part of this warning is took 1.723 seconds: warning says that some coroutine (or task) has freezed your event loop for 1.7 seconds, which is not normal situation (if you don't see why, please read answer here or better here).

As you noted asyncio tracks this problem only when debug mode is on.

Task was destroyed but it is pending!

This warning you'll get regardless of debug mode, it means that at the moment you call loop.close() you still have running tasks. It's again not normal situation (read here to see why).


It's hard to say more without reproducible code snippet.

If you store task in WeakValueDictionary it can be problem, yes. You should properly cancel all tasks (or await them to be finished) before you close event loop.

like image 11
Mikhail Gerasimov Avatar answered Oct 15 '22 01:10

Mikhail Gerasimov