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

2

12

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]>
Plexiform answered 24/11, 2017 at 15:37 Comment(4)
I think I have found the problem. I'm keeping these futures in a WeakValueDictionary. The warning and error disappears if I replace the WeakValueDictionary with a normal dictionary. I think it might have something to do with how the WeakValueDictionary destroys the futures.Plexiform
I'm going to try some stuff.Plexiform
I am facing a similar issue. can you please explain what exactly the issue was and how you solved it.Paez
@HimanshuJain It's been a while since I solved this problem, but if I remember correctly I solved it by changing my code so it doesn't use the weak value dictionary. The futures need to be properly closed which the dictionary wasn't doing.Plexiform
L
11
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.

Licentiate answered 24/11, 2017 at 16:24 Comment(2)
if you have many coroutines, if there any way of knowing which one froze?Jillayne
@TadejMagajna I'm afraid no, at least I don't know how it can be achieved.Licentiate
I
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

Illustrative answered 13/8, 2020 at 17:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.