Skip to content

Commit 97cf082

Browse files
asvetlovmiss-islington
authored andcommitted
bpo-34970: Protect tasks weak set manipulation in asyncio.all_tasks() (pythonGH-9837)
https://bugs.python.org/issue34970
1 parent 1a997eb commit 97cf082

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Lib/asyncio/tasks.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ def all_tasks(loop=None):
4242
"""Return a set of all tasks for the loop."""
4343
if loop is None:
4444
loop = events.get_running_loop()
45-
return {t for t in _all_tasks
45+
# NB: set(_all_tasks) is required to protect
46+
# from https://bugs.python.org/issue34970 bug
47+
return {t for t in list(_all_tasks)
4648
if futures._get_loop(t) is loop and not t.done()}
4749

4850

@@ -52,7 +54,9 @@ def _all_tasks_compat(loop=None):
5254
# method.
5355
if loop is None:
5456
loop = events.get_event_loop()
55-
return {t for t in _all_tasks if futures._get_loop(t) is loop}
57+
# NB: set(_all_tasks) is required to protect
58+
# from https://bugs.python.org/issue34970 bug
59+
return {t for t in list(_all_tasks) if futures._get_loop(t) is loop}
5660

5761

5862
def _set_task_name(task, name):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Protect tasks weak set manipulation in ``asyncio.all_tasks()``

0 commit comments

Comments
 (0)