Skip to content

Commit b32c641

Browse files
committed
run main loop with tornado
asyncio.run doesn't exit when you stop the loop (?!)
1 parent 4343491 commit b32c641

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

ipyparallel/engine/app.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,8 @@ def _signal_stop(self, sig, frame):
970970
# claims to be threadsafe, but is not
971971
kernel_stop = getattr(self.kernel, "stop", None)
972972
if kernel_stop is not None:
973+
self.log.debug("Calling kernel.stop()")
974+
973975
# callback must be async for event loop to be
974976
# detected by anyio
975977
async def stop():
@@ -982,6 +984,7 @@ async def stop():
982984
self.loop.add_callback_from_signal(stop)
983985
if self._kernel_start_future is None:
984986
# not awaiting start_future, stop loop directly
987+
self.log.debug("Stopping event loop")
985988
self.loop.add_callback_from_signal(self.loop.stop)
986989
except Exception:
987990
self.log.critical("Failed to stop kernel", exc_info=True)
@@ -990,7 +993,12 @@ async def stop():
990993
def start(self):
991994
if self.id is not None:
992995
self.log.name += f".{self.id}"
993-
asyncio.run(self._start())
996+
try:
997+
self.loop.run_sync(self._start)
998+
except (asyncio.TimeoutError, KeyboardInterrupt):
999+
# tornado run_sync raises TimeoutError
1000+
# if the task didn't finish
1001+
pass
9941002

9951003
async def _start(self):
9961004
await self.register()

0 commit comments

Comments
 (0)