What does an “Executing <Handle <TaskWakeupMethWrapper…” warning in python asyncio mean

匆匆过客 提交于 2020-08-27 06:03:27

问题


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]>

回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/47476388/what-does-an-executing-handle-taskwakeupmethwrapper-warning-in-python-asy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!