[issue36607] asyncio.all_tasks() crashes if asyncio is used in multiple threads

Andrew Svetlov report at bugs.python.org
Wed Apr 17 14:25:01 EDT 2019


Andrew Svetlov <andrew.svetlov at gmail.com> added the comment:

Thanks for the report!

I see 3 ways to fix the bug:
1. Guard _all_tasks with threading.Lock. It hurts performance significantly.
2. Retry list(_all_tasks) call in a loop if RuntimeError was raised. A chance of collision is very low, the strategy is good enough
3. Change _all_tasks from weak set of tasks to WeakDict[AbstractEventLoop, WeakSet[Task]]. This realization eliminates the collision it is a little complicated. Plus loop should be hashable now (perhaps ok but I'm not sure if all third-party loops support it).

Thus I'm inclining to bullet 2.
THoughts?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36607>
_______________________________________


More information about the Python-bugs-list mailing list