Skip to content

Commit 024ffb0

Browse files
committed
Move watching shell_stop event to start()
1 parent 38405df commit 024ffb0

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

ipykernel/kernelbase.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -419,15 +419,6 @@ async def shell_main(self, subshell_id: str | None):
419419

420420
async with create_task_group() as tg:
421421
tg.start_soon(self.process_shell, socket)
422-
if subshell_id is None:
423-
# Main subshell.
424-
await to_thread.run_sync(self.shell_stop.wait)
425-
426-
if not self._eventloop_set.is_set():
427-
# Stop the async task that is waiting for the eventloop to be set.
428-
self._eventloop_set.set()
429-
430-
tg.cancel_scope.cancel()
431422

432423
async def process_shell(self, socket=None):
433424
# socket=None is valid if kernel subshells are not supported.
@@ -577,6 +568,14 @@ async def start(self, *, task_status: TaskStatus = TASK_STATUS_IGNORED) -> None:
577568
if not self._is_test and self.shell_socket is not None:
578569
tg.start_soon(self.shell_main, None)
579570

571+
await to_thread.run_sync(self.shell_stop.wait)
572+
573+
if not self._eventloop_set.is_set():
574+
# Stop the async task that is waiting for the eventloop to be set.
575+
self._eventloop_set.set()
576+
577+
tg.cancel_scope.cancel()
578+
580579
def stop(self):
581580
self.shell_stop.set()
582581
self.control_stop.set()

0 commit comments

Comments
 (0)