From eba6c5c8732fd64b9b1eed1dc2a60e6dfb1aeae3 Mon Sep 17 00:00:00 2001 From: David Brochart Date: Thu, 7 Nov 2024 22:34:55 +0100 Subject: [PATCH] Use threading.Event for _eventloop_set instead of anyio.Event --- ipykernel/kernelapp.py | 4 ++-- ipykernel/kernelbase.py | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/ipykernel/kernelapp.py b/ipykernel/kernelapp.py index 55efaa8e..b50d6dc4 100644 --- a/ipykernel/kernelapp.py +++ b/ipykernel/kernelapp.py @@ -19,7 +19,7 @@ import zmq import zmq.asyncio -from anyio import create_task_group, run +from anyio import create_task_group, run, to_thread from IPython.core.application import ( # type:ignore[attr-defined] BaseIPythonApplication, base_aliases, @@ -738,7 +738,7 @@ def start(self) -> None: return async def _wait_to_enter_eventloop(self): - await self.kernel._eventloop_set.wait() + await to_thread.run_sync(self.kernel._eventloop_set.wait) await self.kernel.enter_eventloop() async def main(self): diff --git a/ipykernel/kernelbase.py b/ipykernel/kernelbase.py index d496e0c9..5a105719 100644 --- a/ipykernel/kernelbase.py +++ b/ipykernel/kernelbase.py @@ -35,7 +35,7 @@ import psutil import zmq -from anyio import TASK_STATUS_IGNORED, Event, create_task_group, sleep, to_thread +from anyio import TASK_STATUS_IGNORED, create_task_group, sleep, to_thread from anyio.abc import TaskStatus from IPython.core.error import StdinNotImplementedError from jupyter_client.session import Session @@ -226,7 +226,7 @@ def _parent_header(self): "list_subshell_request", ] - _eventloop_set: Event = Event() + _eventloop_set: threading.Event = threading.Event() def __init__(self, **kwargs): """Initialize the kernel.""" @@ -553,9 +553,8 @@ async def start(self, *, task_status: TaskStatus = TASK_STATUS_IGNORED) -> None: tg.start_soon(self.shell_main, None) def stop(self): - if not self._eventloop_set.is_set(): - # Stop the async task that is waiting for the eventloop to be set. - self._eventloop_set.set() + # Stop the async task that is waiting for the eventloop to be set. + self._eventloop_set.set() self.shell_stop.set() self.control_stop.set()