Skip to content

Commit f5d2292

Browse files
committed
do_one_iteration is a coroutine
1 parent ae6836f commit f5d2292

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

ipykernel/eventloops.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ def process_stream_events(stream, *a, **kw):
253253
app.mainloop()
254254

255255
else:
256+
import asyncio
257+
import nest_asyncio
258+
nest_asyncio.apply()
259+
256260
doi = kernel.do_one_iteration
257261
# Tk uses milliseconds
258262
poll_interval = int(1000 * kernel._poll_interval)
@@ -264,7 +268,11 @@ def __init__(self, app, func):
264268
self.func = func
265269

266270
def on_timer(self):
267-
self.func()
271+
loop = asyncio.get_event_loop()
272+
try:
273+
loop.run_until_complete(self.func())
274+
except Exception:
275+
kernel.log.exception("Error in message handler")
268276
self.app.after(poll_interval, self.on_timer)
269277

270278
def start(self):

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def run(self):
7070
'tornado>=4.2,<7.0',
7171
'matplotlib-inline>=0.1.0,<0.2.0',
7272
'appnope;platform_system=="Darwin"',
73+
'nest_asyncio',
7374
],
7475
extras_require={
7576
"test": [

0 commit comments

Comments
 (0)