Skip to content

Commit 06e9cb3

Browse files
Remove usage of jupyter_events (#849)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 5b291a7 commit 06e9cb3

File tree

8 files changed

+11
-145
lines changed

8 files changed

+11
-145
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,4 @@ jobs:
151151
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
152152
- uses: jupyterlab/maintainer-tools/.github/actions/test-sdist@v1
153153
with:
154-
test_command: pytest --vv || pytest -vv --lf
154+
test_command: pytest -vv || pytest -vv --lf

jupyter_client/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
"""Client-side implementations of the Jupyter protocol"""
2-
import pathlib
3-
42
from ._version import __version__ # noqa
53
from ._version import protocol_version # noqa
64
from ._version import protocol_version_info # noqa
75
from ._version import version_info # noqa
86

9-
JUPYTER_CLIENT_EVENTS_URI = "https://events.jupyter.org/jupyter_client"
10-
DEFAULT_EVENTS_SCHEMA_PATH = pathlib.Path(__file__).parent / "event_schemas"
11-
127
try:
138
from .asynchronous import AsyncKernelClient # noqa
149
from .blocking import BlockingKernelClient # noqa

jupyter_client/event_schemas/kernel_manager/v1.yaml

Lines changed: 0 additions & 36 deletions
This file was deleted.

jupyter_client/manager.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from enum import Enum
1616

1717
import zmq
18-
from jupyter_events import EventLogger # type: ignore[import]
1918
from traitlets import Any
2019
from traitlets import Bool
2120
from traitlets import default
@@ -33,8 +32,6 @@
3332
from .provisioning import KernelProvisionerBase
3433
from .provisioning import KernelProvisionerFactory as KPF
3534
from .utils import run_sync
36-
from jupyter_client import DEFAULT_EVENTS_SCHEMA_PATH
37-
from jupyter_client import JUPYTER_CLIENT_EVENTS_URI
3835
from jupyter_client import KernelClient
3936
from jupyter_client import kernelspec
4037

@@ -94,27 +91,6 @@ class KernelManager(ConnectionFileMixin):
9491
This version starts kernels with Popen.
9592
"""
9693

97-
event_schema_id = JUPYTER_CLIENT_EVENTS_URI + "/kernel_manager/v1"
98-
event_logger = Instance(EventLogger).tag(config=True)
99-
100-
@default("event_logger")
101-
def _default_event_logger(self):
102-
if self.parent and hasattr(self.parent, "event_logger"):
103-
return self.parent.event_logger
104-
else:
105-
# If parent does not have an event logger, create one.
106-
logger = EventLogger()
107-
schema_path = DEFAULT_EVENTS_SCHEMA_PATH / "kernel_manager" / "v1.yaml"
108-
logger.register_event_schema(schema_path)
109-
return logger
110-
111-
def _emit(self, *, action: str) -> None:
112-
"""Emit event using the core event schema from Jupyter Server's Contents Manager."""
113-
self.event_logger.emit(
114-
schema_id=self.event_schema_id,
115-
data={"action": action, "kernel_id": self.kernel_id, "caller": "kernel_manager"},
116-
)
117-
11894
_ready: t.Union[Future, CFuture]
11995

12096
def __init__(self, *args, **kwargs):
@@ -333,7 +309,6 @@ async def _async_launch_kernel(self, kernel_cmd: t.List[str], **kw: t.Any) -> No
333309
assert self.provisioner.has_process
334310
# Provisioner provides the connection information. Load into kernel manager and write file.
335311
self._force_connection_info(connection_info)
336-
self._emit(action="launch")
337312

338313
_launch_kernel = run_sync(_async_launch_kernel)
339314

@@ -376,7 +351,6 @@ async def _async_pre_start_kernel(
376351
)
377352
kw = await self.provisioner.pre_launch(**kw)
378353
kernel_cmd = kw.pop('cmd')
379-
self._emit(action="pre_start")
380354
return kernel_cmd, kw
381355

382356
pre_start_kernel = run_sync(_async_pre_start_kernel)
@@ -393,7 +367,6 @@ async def _async_post_start_kernel(self, **kw: t.Any) -> None:
393367
self._connect_control_socket()
394368
assert self.provisioner is not None
395369
await self.provisioner.post_launch(**kw)
396-
self._emit(action="post_start")
397370

398371
post_start_kernel = run_sync(_async_post_start_kernel)
399372

@@ -430,7 +403,6 @@ async def _async_request_shutdown(self, restart: bool = False) -> None:
430403
assert self.provisioner is not None
431404
await self.provisioner.shutdown_requested(restart=restart)
432405
self._shutdown_status = _ShutdownStatus.ShutdownRequest
433-
self._emit(action="request_shutdown")
434406

435407
request_shutdown = run_sync(_async_request_shutdown)
436408

@@ -472,7 +444,6 @@ async def _async_finish_shutdown(
472444
if self.has_kernel:
473445
assert self.provisioner is not None
474446
await self.provisioner.wait()
475-
self._emit(action="finish_shutdown")
476447

477448
finish_shutdown = run_sync(_async_finish_shutdown)
478449

@@ -490,7 +461,6 @@ async def _async_cleanup_resources(self, restart: bool = False) -> None:
490461

491462
if self.provisioner:
492463
await self.provisioner.cleanup(restart=restart)
493-
self._emit(action="cleanup_resources")
494464

495465
cleanup_resources = run_sync(_async_cleanup_resources)
496466

@@ -513,7 +483,6 @@ async def _async_shutdown_kernel(self, now: bool = False, restart: bool = False)
513483
Will this kernel be restarted after it is shutdown. When this
514484
is True, connection files will not be cleaned up.
515485
"""
516-
self._emit(action="shutdown_started")
517486
self.shutting_down = True # Used by restarter to prevent race condition
518487
# Stop monitoring for restarting while we shutdown.
519488
self.stop_restarter()
@@ -531,7 +500,6 @@ async def _async_shutdown_kernel(self, now: bool = False, restart: bool = False)
531500
await self._async_finish_shutdown(restart=restart)
532501

533502
await self._async_cleanup_resources(restart=restart)
534-
self._emit(action="shutdown_finished")
535503

536504
shutdown_kernel = run_sync(_async_shutdown_kernel)
537505

@@ -562,7 +530,6 @@ async def _async_restart_kernel(
562530
Any options specified here will overwrite those used to launch the
563531
kernel.
564532
"""
565-
self._emit(action="restart_started")
566533
if self._launch_args is None:
567534
raise RuntimeError("Cannot restart the kernel. No previous call to 'start_kernel'.")
568535

@@ -575,7 +542,6 @@ async def _async_restart_kernel(
575542
# Start new kernel.
576543
self._launch_args.update(kw)
577544
await self._async_start_kernel(**self._launch_args)
578-
self._emit(action="restart_finished")
579545

580546
restart_kernel = run_sync(_async_restart_kernel)
581547

@@ -612,7 +578,6 @@ async def _async_kill_kernel(self, restart: bool = False) -> None:
612578
# Process is no longer alive, wait and clear
613579
if self.has_kernel:
614580
await self.provisioner.wait()
615-
self._emit(action="kill")
616581

617582
_kill_kernel = run_sync(_async_kill_kernel)
618583

@@ -634,7 +599,6 @@ async def _async_interrupt_kernel(self) -> None:
634599
self.session.send(self._control_socket, msg)
635600
else:
636601
raise RuntimeError("Cannot interrupt kernel. No kernel is running!")
637-
self._emit(action="interrupt")
638602

639603
interrupt_kernel = run_sync(_async_interrupt_kernel)
640604

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ dependencies = [
3030
"pyzmq>=23.0",
3131
"tornado>=6.2",
3232
"traitlets",
33-
"jupyter_events>=0.5.0"
3433
]
3534

3635
[[project.authors]]
@@ -59,7 +58,6 @@ test = [
5958
"pytest-asyncio>=0.19",
6059
"pytest-cov",
6160
"pytest-timeout",
62-
"jupyter_events[test]"
6361
]
6462
doc = [
6563
"ipykernel",

tests/conftest.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
pjoin = os.path.join
1717

1818

19-
pytest_plugins = ["jupyter_events.pytest_plugin"]
20-
21-
2219
# Handle resource limit
2320
# Ensure a minimal soft limit of DEFAULT_SOFT if the current hard limit is at least that much.
2421
if resource is not None:

tests/test_kernelmanager.py

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from .utils import AsyncKMSubclass
1919
from .utils import SyncKMSubclass
2020
from jupyter_client import AsyncKernelManager
21-
from jupyter_client import DEFAULT_EVENTS_SCHEMA_PATH
2221
from jupyter_client import KernelManager
2322
from jupyter_client.manager import _ShutdownStatus
2423
from jupyter_client.manager import start_new_async_kernel
@@ -93,14 +92,14 @@ def start_kernel():
9392

9493

9594
@pytest.fixture
96-
def km(config, jp_event_logger):
97-
km = KernelManager(config=config, event_logger=jp_event_logger)
95+
def km(config):
96+
km = KernelManager(config=config)
9897
return km
9998

10099

101100
@pytest.fixture
102-
def km_subclass(config, jp_event_logger):
103-
km = SyncKMSubclass(config=config, event_logger=jp_event_logger)
101+
def km_subclass(config):
102+
km = SyncKMSubclass(config=config)
104103
return km
105104

106105

@@ -113,36 +112,15 @@ def zmq_context():
113112
ctx.term()
114113

115114

116-
@pytest.fixture
117-
def jp_event_schemas():
118-
return [DEFAULT_EVENTS_SCHEMA_PATH / "kernel_manager" / "v1.yaml"]
119-
120-
121-
@pytest.fixture
122-
def check_emitted_events(jp_read_emitted_events):
123-
"""Check the given events where emitted"""
124-
125-
def _(*expected_list):
126-
read_events = jp_read_emitted_events()
127-
events = [e for e in read_events if e["caller"] == "kernel_manager"]
128-
# Ensure that the number of read events match the expected events.
129-
assert len(events) == len(expected_list)
130-
# Loop through the events and make sure they are in order of expected.
131-
for i, action in enumerate(expected_list):
132-
assert "action" in events[i] and action == events[i]["action"]
133-
134-
return _
135-
136-
137115
@pytest.fixture(params=[AsyncKernelManager, AsyncKMSubclass])
138-
def async_km(request, config, jp_event_logger):
139-
km = request.param(config=config, event_logger=jp_event_logger)
116+
async def async_km(request, config):
117+
km = request.param(config=config)
140118
return km
141119

142120

143121
@pytest.fixture
144-
def async_km_subclass(config, jp_event_logger):
145-
km = AsyncKMSubclass(config=config, event_logger=jp_event_logger)
122+
async def async_km_subclass(config):
123+
km = AsyncKMSubclass(config=config)
146124
return km
147125

148126

@@ -214,35 +192,18 @@ async def test_async_signal_kernel_subprocesses(self, name, install, expected):
214192

215193

216194
class TestKernelManager:
217-
def test_lifecycle(self, km, jp_read_emitted_events, check_emitted_events):
195+
def test_lifecycle(self, km):
218196
km.start_kernel(stdout=PIPE, stderr=PIPE)
219-
check_emitted_events("pre_start", "launch", "post_start")
220197
kc = km.client()
221198
assert km.is_alive()
222199
is_done = km.ready.done()
223200
assert is_done
224201
km.restart_kernel(now=True)
225-
check_emitted_events(
226-
"restart_started",
227-
"shutdown_started",
228-
"interrupt",
229-
"kill",
230-
"cleanup_resources",
231-
"shutdown_finished",
232-
"pre_start",
233-
"launch",
234-
"post_start",
235-
"restart_finished",
236-
)
237202
assert km.is_alive()
238203
km.interrupt_kernel()
239-
check_emitted_events("interrupt")
240204
assert isinstance(km, KernelManager)
241205
kc.stop_channels()
242206
km.shutdown_kernel(now=True)
243-
check_emitted_events(
244-
"shutdown_started", "interrupt", "kill", "cleanup_resources", "shutdown_finished"
245-
)
246207
assert km.context.closed
247208

248209
def test_get_connect_info(self, km):
@@ -482,10 +443,7 @@ def execute(cmd):
482443

483444
@pytest.mark.asyncio
484445
class TestAsyncKernelManager:
485-
async def test_lifecycle(
486-
self,
487-
async_km,
488-
):
446+
async def test_lifecycle(self, async_km):
489447
await async_km.start_kernel(stdout=PIPE, stderr=PIPE)
490448
is_alive = await async_km.is_alive()
491449
assert is_alive

tests/test_manager.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,3 @@ def test_connection_file_real_path():
3232
km._launch_args = {}
3333
cmds = km.format_kernel_cmd()
3434
assert cmds[4] == "foobar"
35-
36-
37-
def test_kernel_manager_event_logger(jp_event_handler, jp_read_emitted_events):
38-
action = "pre_start"
39-
km = KernelManager()
40-
km.event_logger.register_handler(jp_event_handler)
41-
km._emit(action=action)
42-
output = jp_read_emitted_events()[0]
43-
assert "kernel_id" in output and output["kernel_id"] is None
44-
assert "action" in output and output["action"] == action

0 commit comments

Comments
 (0)