summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/tasks.py
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2018-10-13 18:12:40 (GMT)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-10-13 18:12:40 (GMT)
commit97cf0828727ac2a269c89c5aa09570a69a22c83c (patch)
treeea2c5f3adc78a8cfb8fb763602af87166c1d0b3d /Lib/asyncio/tasks.py
parent1a997eb291fdc5f5606c898fffbde61d899ed762 (diff)
downloadcpython-97cf0828727ac2a269c89c5aa09570a69a22c83c.zip
cpython-97cf0828727ac2a269c89c5aa09570a69a22c83c.tar.gz
cpython-97cf0828727ac2a269c89c5aa09570a69a22c83c.tar.bz2
bpo-34970: Protect tasks weak set manipulation in asyncio.all_tasks() (GH-9837)
https://bugs.python.org/issue34970
Diffstat (limited to 'Lib/asyncio/tasks.py')
-rw-r--r--Lib/asyncio/tasks.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
index 743e82b..15422da 100644
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -42,7 +42,9 @@ def all_tasks(loop=None):
"""Return a set of all tasks for the loop."""
if loop is None:
loop = events.get_running_loop()
- return {t for t in _all_tasks
+ # NB: set(_all_tasks) is required to protect
+ # from https://bugs.python.org/issue34970 bug
+ return {t for t in list(_all_tasks)
if futures._get_loop(t) is loop and not t.done()}
@@ -52,7 +54,9 @@ def _all_tasks_compat(loop=None):
# method.
if loop is None:
loop = events.get_event_loop()
- return {t for t in _all_tasks if futures._get_loop(t) is loop}
+ # NB: set(_all_tasks) is required to protect
+ # from https://bugs.python.org/issue34970 bug
+ return {t for t in list(_all_tasks) if futures._get_loop(t) is loop}
def _set_task_name(task, name):