From f5d229220c69000f987759ede8295e6f8509a70e Mon Sep 17 00:00:00 2001 From: Quentin Peter Date: Mon, 3 Jan 2022 18:58:04 +0100 Subject: [PATCH] do_one_iteration is a coroutine --- ipykernel/eventloops.py | 10 +++++++++- setup.py | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ipykernel/eventloops.py b/ipykernel/eventloops.py index 45a978123..29434bb41 100644 --- a/ipykernel/eventloops.py +++ b/ipykernel/eventloops.py @@ -253,6 +253,10 @@ def process_stream_events(stream, *a, **kw): app.mainloop() else: + import asyncio + import nest_asyncio + nest_asyncio.apply() + doi = kernel.do_one_iteration # Tk uses milliseconds poll_interval = int(1000 * kernel._poll_interval) @@ -264,7 +268,11 @@ def __init__(self, app, func): self.func = func def on_timer(self): - self.func() + loop = asyncio.get_event_loop() + try: + loop.run_until_complete(self.func()) + except Exception: + kernel.log.exception("Error in message handler") self.app.after(poll_interval, self.on_timer) def start(self): diff --git a/setup.py b/setup.py index fc2828660..f2c0719c7 100644 --- a/setup.py +++ b/setup.py @@ -70,6 +70,7 @@ def run(self): 'tornado>=4.2,<7.0', 'matplotlib-inline>=0.1.0,<0.2.0', 'appnope;platform_system=="Darwin"', + 'nest_asyncio', ], extras_require={ "test": [