Skip to content

Commit

Permalink
Set async event in async context
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Feb 21, 2025
1 parent f13f7d7 commit c9e9108
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ipykernel/kernelapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ async def _start(self, backend: str) -> None:

def start(self) -> None:
"""Start the application."""
backend = "trio" if self.trio_loop else "asyncio"
backend = "trio"# if self.trio_loop else "asyncio"
run(partial(self._start, backend), backend=backend)

async def _wait_to_enter_eventloop(self) -> None:
Expand Down
9 changes: 5 additions & 4 deletions ipykernel/kernelbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@ async def shell_main(self, subshell_id: str | None):
if subshell_id is None:
# Main subshell.
await to_thread.run_sync(self.shell_stop.wait)

if not self._eventloop_set.is_set():
# Stop the async task that is waiting for the eventloop to be set.
self._eventloop_set.set()

tg.cancel_scope.cancel()

async def process_shell(self, socket=None):
Expand Down Expand Up @@ -573,10 +578,6 @@ 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()

self.shell_stop.set()
self.control_stop.set()

Expand Down

0 comments on commit c9e9108

Please sign in to comment.