diff --git a/jupyter_core/utils/patched_nest_asyncio.py b/jupyter_core/utils/patched_nest_asyncio.py index fee2530..6e0163f 100644 --- a/jupyter_core/utils/patched_nest_asyncio.py +++ b/jupyter_core/utils/patched_nest_asyncio.py @@ -2,7 +2,6 @@ # Distributed under the terms of the Modified BSD License. # Note: copied from https://github.com/ipyflow/ipyflow/blob/8e4bc5cb8d4231b9b69f4f9dce867b8101164ac5/core/ipyflow/kernel/patched_nest_asyncio.py import asyncio -import sys def apply(loop=None): @@ -29,19 +28,15 @@ def step(task, exc=None): curr_tasks[task._loop] = curr_task Task = asyncio.Task - if sys.version_info >= (3, 7, 0): + def enter_task(loop, task): + curr_tasks[loop] = task - def enter_task(loop, task): - curr_tasks[loop] = task + def leave_task(loop, task): + curr_tasks.pop(loop, None) - def leave_task(loop, task): - curr_tasks.pop(loop, None) - - asyncio.tasks._enter_task = enter_task - asyncio.tasks._leave_task = leave_task - curr_tasks = asyncio.tasks._current_tasks # noqa - else: - curr_tasks = Task._current_tasks # noqa + asyncio.tasks._enter_task = enter_task + asyncio.tasks._leave_task = leave_task + curr_tasks = asyncio.tasks._current_tasks # noqa try: step_orig = Task._Task__step # noqa Task._Task__step = step # noqa