Use variable instead of monkey patching asyncio

This commit is contained in:
coffeebenzene
2020-12-02 19:50:49 +00:00
parent ed6231d3aa
commit f866bbcf45
2 changed files with 11 additions and 9 deletions

View File

@@ -31,10 +31,11 @@ from tornado.platform.asyncio import to_asyncio_future
# For compatibility with python versions 3.6 or earlier.
# asyncio.Task.all_tasks() is fully moved to asyncio.all_tasks() starting with 3.9. Also applies to current_task.
try:
asyncio.all_tasks
asyncio_all_tasks = asyncio.all_tasks
asyncio_current_task = asyncio.current_task
except AttributeError as e:
asyncio.all_tasks = asyncio.Task.all_tasks
asyncio.current_task = asyncio.Task.current_task
asyncio_all_tasks = asyncio.Task.all_tasks
asyncio_current_task = asyncio.Task.current_task
def random_port():
@@ -482,7 +483,7 @@ def print_stacks(file=sys.stderr):
# also show asyncio tasks, if any
# this will increase over time as we transition from tornado
# coroutines to native `async def`
tasks = asyncio.all_tasks()
tasks = asyncio_all_tasks()
if tasks:
print("AsyncIO tasks: %i" % len(tasks))
for task in tasks: