Skip to content

Commit f2a2cce

Browse files
Frédéric Collonvalfcollonval
andauthored
Fix handling (not) owned kernel (#8)
Co-authored-by: Frédéric Collonval <[email protected]>
1 parent ee8e8bd commit f2a2cce

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

jupyter_kernel_client/client.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from __future__ import annotations
66

77
import datetime
8+
import logging
89
import typing as t
910
from functools import partial
1011

@@ -15,6 +16,8 @@
1516
from .manager import KernelHttpManager
1617
from .utils import UTC
1718

19+
logger = logging.getLogger("jupyter_kernel_client")
20+
1821

1922
def output_hook(outputs: list[dict[str, t.Any]], message: dict[str, t.Any]) -> set[int]: # noqa: C901
2023
"""Callback on messages captured during a code snippet execution.
@@ -154,10 +157,14 @@ class KernelClient(LoggingConfigurable):
154157
help="The kernel manager class to use.",
155158
)
156159

157-
def __init__(self, kernel_id: str | None = None, **kwargs) -> None:
158-
super().__init__()
159-
self._own_kernel = bool(kernel_id)
160+
def __init__(
161+
self, kernel_id: str | None = None, log: logging.Logger | None = None, **kwargs
162+
) -> None:
163+
super().__init__(log=log or logger)
160164
self._manager = self.kernel_manager_class(parent=self, kernel_id=kernel_id, **kwargs)
165+
# Set it after the manager as if a kernel_id is provided,
166+
# we will try to connect to it.
167+
self._own_kernel = self._manager.kernel is None
161168

162169
def __del__(self) -> None:
163170
self.stop()

0 commit comments

Comments
 (0)