]> granicus.if.org Git - python/commitdiff
bpo-34970: Protect tasks weak set manipulation in asyncio.all_tasks() (GH-9837)
authorAndrew Svetlov <andrew.svetlov@gmail.com>
Sat, 13 Oct 2018 18:12:40 +0000 (21:12 +0300)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 13 Oct 2018 18:12:40 +0000 (11:12 -0700)
https://bugs.python.org/issue34970

Lib/asyncio/tasks.py
Misc/NEWS.d/next/Library/2018-10-13-11-14-13.bpo-34970.SrJTY7.rst [new file with mode: 0644]

index 743e82baff7aac0692a85d33398069126fcfb2c4..15422da1b3b2e0015c6cd5a33278f4ba5f824ca7 100644 (file)
@@ -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):
diff --git a/Misc/NEWS.d/next/Library/2018-10-13-11-14-13.bpo-34970.SrJTY7.rst b/Misc/NEWS.d/next/Library/2018-10-13-11-14-13.bpo-34970.SrJTY7.rst
new file mode 100644 (file)
index 0000000..a58b3dd
--- /dev/null
@@ -0,0 +1 @@
+Protect tasks weak set manipulation in ``asyncio.all_tasks()``