Skip to content

Commit ac7776d

Browse files
authored
Restore nest-asyncio for tk loop (#1086)
restore nest-asyncio for tk loop
1 parent 2f9eb16 commit ac7776d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

ipykernel/eventloops.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from functools import partial
1010

1111
import zmq
12-
from jupyter_core.utils import run_sync
1312
from packaging.version import Version as V # noqa
1413
from traitlets.config.application import Application
1514

@@ -251,6 +250,12 @@ def process_stream_events(stream, *a, **kw):
251250
app.mainloop()
252251

253252
else:
253+
import asyncio
254+
255+
import nest_asyncio
256+
257+
nest_asyncio.apply()
258+
254259
doi = kernel.do_one_iteration
255260
# Tk uses milliseconds
256261
poll_interval = int(1000 * kernel._poll_interval)
@@ -262,8 +267,9 @@ def __init__(self, app, func):
262267
self.func = func
263268

264269
def on_timer(self):
270+
loop = asyncio.get_event_loop()
265271
try:
266-
run_sync(self.func)()
272+
loop.run_until_complete(self.func())
267273
except Exception:
268274
kernel.log.exception("Error in message handler")
269275
self.app.after(poll_interval, self.on_timer)

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ dependencies = [
3131
"traitlets>=5.4.0",
3232
"jupyter_client>=6.1.12",
3333
"jupyter_core>=4.12,!=5.0.*",
34+
# For tk event loop support only.
35+
"nest_asyncio",
3436
"tornado>=6.1",
3537
"matplotlib-inline>=0.1",
3638
'appnope;platform_system=="Darwin"',

0 commit comments

Comments
 (0)