Skip to content

Commit 8f832ac

Browse files
committed
Fix asyncio error when opening notebooks
This is a fix for jupyter/notebook#6164 We are only applying `nest_asyncio` when `run_sync` has been called which means there could be tasks queued that are unpatched e.g. from the original issue: ``` <Task pending coro=<HTTP1ServerConnection._server_request_loop() running at /apps/python3/lib/python3.7/site-packages/tornado/http1connection.py:823> ``` which originates from Tornado. A similar issue was reported in `nest-asyncio`: erdewit/nest_asyncio#22 where the solution is to call `apply` on import so that unpatched tasks do not get created.
1 parent f453b51 commit 8f832ac

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

jupyter_client/utils.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import inspect
88
import os
99

10+
import nest_asyncio # type: ignore
11+
12+
nest_asyncio.apply()
13+
1014

1115
def run_sync(coro):
1216
def wrapped(*args, **kwargs):
@@ -15,7 +19,6 @@ def wrapped(*args, **kwargs):
1519
except RuntimeError:
1620
loop = asyncio.new_event_loop()
1721
asyncio.set_event_loop(loop)
18-
import nest_asyncio # type: ignore
1922

2023
nest_asyncio.apply(loop)
2124
future = asyncio.ensure_future(coro(*args, **kwargs))

0 commit comments

Comments
 (0)