Fix PendingDeprecationWarning: Task.all_tasks() is deprecated, use asyncio.all_tasks() instead (#741)
This commit is contained in:
parent
53e72102e9
commit
d00eac9944
6
black.py
6
black.py
@ -3423,8 +3423,12 @@ def cancel(tasks: Iterable[asyncio.Task]) -> None:
|
|||||||
def shutdown(loop: BaseEventLoop) -> None:
|
def shutdown(loop: BaseEventLoop) -> None:
|
||||||
"""Cancel all pending tasks on `loop`, wait for them, and close the loop."""
|
"""Cancel all pending tasks on `loop`, wait for them, and close the loop."""
|
||||||
try:
|
try:
|
||||||
|
if sys.version_info[:2] >= (3, 7):
|
||||||
|
all_tasks = asyncio.all_tasks
|
||||||
|
else:
|
||||||
|
all_tasks = asyncio.Task.all_tasks
|
||||||
# This part is borrowed from asyncio/runners.py in Python 3.7b2.
|
# This part is borrowed from asyncio/runners.py in Python 3.7b2.
|
||||||
to_cancel = [task for task in asyncio.Task.all_tasks(loop) if not task.done()]
|
to_cancel = [task for task in all_tasks(loop) if not task.done()]
|
||||||
if not to_cancel:
|
if not to_cancel:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user