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 4fec5b7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 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
7 changes: 3 additions & 4 deletions ipykernel/kernelbase.py
Original file line number Diff line number Diff line change
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 4fec5b7

Please sign in to comment.