summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/tasks.py
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2018-05-28 21:54:02 (GMT)
committerGitHub <noreply@github.com>2018-05-28 21:54:02 (GMT)
commit416c1ebd9896b394790dcb4f9f035b1a44ebe9ff (patch)
treea5003eed8be41259a0e545fde1c2d22bf2ac23c7 /Lib/asyncio/tasks.py
parentfdccfe09f0b10776645fdb04a0783d6864c32b21 (diff)
downloadcpython-416c1ebd9896b394790dcb4f9f035b1a44ebe9ff.zip
cpython-416c1ebd9896b394790dcb4f9f035b1a44ebe9ff.tar.gz
cpython-416c1ebd9896b394790dcb4f9f035b1a44ebe9ff.tar.bz2
bpo-32610: Fix asyncio.all_tasks() to return only pending tasks. (GH-7174)
Diffstat (limited to 'Lib/asyncio/tasks.py')
-rw-r--r--Lib/asyncio/tasks.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
index 4a9db2a..67fb57c 100644
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -34,6 +34,16 @@ def current_task(loop=None):
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
+ if futures._get_loop(t) is loop and not t.done()}
+
+
+def _all_tasks_compat(loop=None):
+ # Different from "all_task()" by returning *all* Tasks, including
+ # the completed ones. Used to implement deprecated "Tasks.all_task()"
+ # method.
+ if loop is None:
loop = events.get_event_loop()
return {t for t in _all_tasks if futures._get_loop(t) is loop}
@@ -82,7 +92,7 @@ class Task(futures._PyFuture): # Inherit Python Task implementation
"use asyncio.all_tasks() instead",
PendingDeprecationWarning,
stacklevel=2)
- return all_tasks(loop)
+ return _all_tasks_compat(loop)
def __init__(self, coro, *, loop=None):
super().__init__(loop=loop)