Skip to content

Commit 6853f39

Browse files
committed
Merge branch 'main' into zmq_anyio
2 parents 21fd27a + 7a18189 commit 6853f39

File tree

7 files changed

+16
-14
lines changed

7 files changed

+16
-14
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ repos:
2222
- id: trailing-whitespace
2323

2424
- repo: https://github.com/python-jsonschema/check-jsonschema
25-
rev: 0.31.1
25+
rev: 0.31.2
2626
hooks:
2727
- id: check-github-workflows
2828

@@ -74,7 +74,7 @@ repos:
7474
- id: rst-inline-touching-normal
7575

7676
- repo: https://github.com/astral-sh/ruff-pre-commit
77-
rev: v0.2.0
77+
rev: v0.9.7
7878
hooks:
7979
- id: ruff
8080
types_or: [python, jupyter]
@@ -83,7 +83,7 @@ repos:
8383
types_or: [python, jupyter]
8484

8585
- repo: https://github.com/scientific-python/cookie
86-
rev: "2024.01.24"
86+
rev: "2025.01.22"
8787
hooks:
8888
- id: sp-repo-review
8989
additional_dependencies: ["repo-review[cli]"]

ipykernel/_version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
store the current version info of the server.
33
"""
4+
45
from __future__ import annotations
56

67
import re

ipykernel/inprocess/client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# Imports
1212
# -----------------------------------------------------------------------------
1313

14-
1514
from typing import Any, Optional
1615

1716
from jupyter_client.client import KernelClient

ipykernel/ipkernel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,9 +764,9 @@ def run_closure(self: threading.Thread):
764764
for stream in [stdout, stderr]:
765765
if isinstance(stream, OutStream):
766766
if parent == kernel_thread_ident:
767-
stream._thread_to_parent_header[
768-
self.ident
769-
] = kernel._new_threads_parent_header
767+
stream._thread_to_parent_header[self.ident] = (
768+
kernel._new_threads_parent_header
769+
)
770770
else:
771771
stream._thread_to_parent[self.ident] = parent
772772
_threading_Thread_run(self)

ipykernel/kernelapp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import zmq
2222
import zmq_anyio
23-
from anyio import create_task_group, run
23+
from anyio import create_task_group, run, to_thread
2424
from IPython.core.application import ( # type:ignore[attr-defined]
2525
BaseIPythonApplication,
2626
base_aliases,
@@ -765,7 +765,7 @@ def start(self) -> None:
765765
run(partial(self._start, backend), backend=backend)
766766

767767
async def _wait_to_enter_eventloop(self) -> None:
768-
await self.kernel._eventloop_set.wait()
768+
await to_thread.run_sync(self.kernel._eventloop_set.wait)
769769
await self.kernel.enter_eventloop()
770770

771771
async def main(self) -> None:

ipykernel/kernelbase.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import psutil
3838
import zmq
3939
import zmq_anyio
40-
from anyio import TASK_STATUS_IGNORED, Event, create_task_group, sleep, to_thread
40+
from anyio import TASK_STATUS_IGNORED, create_task_group, sleep, to_thread
4141
from anyio.abc import TaskStatus
4242
from IPython.core.error import StdinNotImplementedError
4343
from jupyter_client.session import Session
@@ -236,12 +236,14 @@ def _parent_header(self):
236236
"list_subshell_request",
237237
]
238238

239-
_eventloop_set: Event = Event()
239+
_eventloop_set: threading.Event
240240

241241
def __init__(self, **kwargs):
242242
"""Initialize the kernel."""
243243
super().__init__(**kwargs)
244244

245+
self._eventloop_set = threading.Event()
246+
245247
# Kernel application may swap stdout and stderr to OutStream,
246248
# which is the case in `IPKernelApp.init_io`, hence `sys.stdout`
247249
# can already by different from TextIO at initialization time.

tests/test_kernelapp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ def test_start_app():
3636
def trigger_stop():
3737
time.sleep(1)
3838
app.stop()
39-
print("stopped from thread")
4039

4140
thread = threading.Thread(target=trigger_stop)
41+
t0 = time.time()
4242
thread.start()
4343
app.init_sockets()
44-
print("starting")
4544
app.start()
46-
print("stopped")
45+
t1 = time.time()
46+
assert t1 - t0 >= 1
4747
app.cleanup_connection_file()
4848
app.kernel.destroy()
4949
app.close()

0 commit comments

Comments
 (0)