mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-32610: Fix asyncio.all_tasks() to return only pending tasks. (GH-7174)
This commit is contained in:
parent
fdccfe09f0
commit
416c1ebd98
7 changed files with 51 additions and 9 deletions
|
@ -33,6 +33,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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue