Fix PendingDeprecationWarning: Task.all_tasks() is deprecated, use asyncio.all_tasks() instead (#741)

This commit is contained in:
Hugo 2019-03-14 14:41:42 +02:00 committed by Łukasz Langa
parent 53e72102e9
commit d00eac9944

View File

@ -3423,8 +3423,12 @@ def cancel(tasks: Iterable[asyncio.Task]) -> None:
def shutdown(loop: BaseEventLoop) -> None:
"""Cancel all pending tasks on `loop`, wait for them, and close the loop."""
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.
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:
return