From e22861ac8d1847c26ee6a0441f1ab73f22fdd232 Mon Sep 17 00:00:00 2001 From: David Brochart Date: Tue, 17 Dec 2024 09:54:16 +0100 Subject: [PATCH] - --- ipykernel/kernelbase.py | 2 +- ipykernel/subshell_manager.py | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/ipykernel/kernelbase.py b/ipykernel/kernelbase.py index ed78fc21..3ac67130 100644 --- a/ipykernel/kernelbase.py +++ b/ipykernel/kernelbase.py @@ -556,7 +556,7 @@ async def start(self, *, task_status: TaskStatus = TASK_STATUS_IGNORED) -> None: manager = self.shell_channel_thread.manager self.shell_channel_thread.start_soon(self.shell_channel_thread_main) self.shell_channel_thread.start_soon( - partial(manager.listen_from_control, self.shell_main, self.shell_channel_thread) + partial(manager.listen_from_control, self.shell_main) ) self.shell_channel_thread.start_soon(manager.listen_from_subshells) self.shell_channel_thread.start() diff --git a/ipykernel/subshell_manager.py b/ipykernel/subshell_manager.py index 505c2f40..2636d157 100644 --- a/ipykernel/subshell_manager.py +++ b/ipykernel/subshell_manager.py @@ -125,20 +125,18 @@ def list_subshell(self) -> list[str]: with self._lock_cache: return list(self._cache) - async def listen_from_control(self, subshell_task: t.Any, thread: BaseThread) -> None: + async def listen_from_control(self, subshell_task: t.Any) -> None: """Listen for messages on the control inproc socket, handle those messages and return replies on the same socket. Runs in the shell channel thread. """ assert current_thread().name == SHELL_CHANNEL_THREAD_NAME - if not self._control_shell_channel_socket.started.is_set(): - thread.start_soon(self._control_shell_channel_socket.start) - await self._control_shell_channel_socket.started.wait() socket = self._control_shell_channel_socket - while True: - request = await socket.arecv_json() - reply = await self._process_control_request(request, subshell_task) - await socket.asend_json(reply) + async with socket: + while True: + request = await socket.arecv_json() + reply = await self._process_control_request(request, subshell_task) + await socket.asend_json(reply) async def listen_from_subshells(self) -> None: """Listen for reply messages on inproc sockets of all subshells and resend