Skip to content

Commit

Permalink
Use threading.Event for _eventloop_set instead of anyio.Event
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Nov 7, 2024
1 parent c353ddf commit eba6c5c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions ipykernel/kernelapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
9 changes: 4 additions & 5 deletions ipykernel/kernelbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit eba6c5c

Please sign in to comment.