Skip to content

Commit a11ec5d

Browse files
committed
Change BlockingKernelManager back to KernelManager
1 parent ab25bd6 commit a11ec5d

File tree

6 files changed

+37
-38
lines changed

6 files changed

+37
-38
lines changed

jupyter_client/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from .connect import *
55
from .launcher import *
66
from .client import KernelClient
7-
from .manager import KernelManager, BlockingKernelManager, AsyncKernelManager, run_kernel
7+
from .manager import KernelManager, AsyncKernelManager, run_kernel
88
from .blocking import BlockingKernelClient
99
from .asynchronous import AsyncKernelClient
1010
from .multikernelmanager import MultiKernelManager, AsyncMultiKernelManager

jupyter_client/consoleapp.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
from .blocking import BlockingKernelClient
2727
from .restarter import KernelRestarter
28-
from . import BlockingKernelManager, tunnel_to_kernel, find_connection_file, connect
28+
from . import KernelManager, tunnel_to_kernel, find_connection_file, connect
2929
from .kernelspec import NoSuchKernel
3030
from .session import Session
3131

@@ -86,7 +86,7 @@
8686
# Classes
8787
#-----------------------------------------------------------------------------
8888

89-
classes = [BlockingKernelManager, KernelRestarter, Session]
89+
classes = [KernelManager, KernelRestarter, Session]
9090

9191
class JupyterConsoleApp(ConnectionFileMixin):
9292
name = 'jupyter-console-mixin'
@@ -112,7 +112,7 @@ class JupyterConsoleApp(ConnectionFileMixin):
112112
flags = Dict(flags)
113113
aliases = Dict(aliases)
114114
kernel_manager_class = Type(
115-
default_value=BlockingKernelManager,
115+
default_value=KernelManager,
116116
config=True,
117117
help='The kernel manager class to use.'
118118
)

jupyter_client/kernelapp.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
from . import __version__
1010
from .kernelspec import KernelSpecManager, NATIVE_KERNEL_NAME
11-
from .manager import BlockingKernelManager
11+
from .manager import KernelManager
1212

1313
class KernelApp(JupyterApp):
1414
"""Launch a kernel by name in a local subprocess.
1515
"""
1616
version = __version__
1717
description = "Run a kernel locally in a subprocess"
1818

19-
classes = [BlockingKernelManager, KernelSpecManager]
19+
classes = [KernelManager, KernelSpecManager]
2020

2121
aliases = {
2222
'kernel': 'KernelApp.kernel_name',
@@ -33,8 +33,8 @@ def initialize(self, argv=None):
3333

3434
cf_basename = 'kernel-%s.json' % uuid.uuid4()
3535
self.config.setdefault('KernelManager', {}).setdefault('connection_file', os.path.join(self.runtime_dir, cf_basename))
36-
self.km = BlockingKernelManager(kernel_name=self.kernel_name,
37-
config=self.config)
36+
self.km = KernelManager(kernel_name=self.kernel_name,
37+
config=self.config)
3838

3939
self.loop = IOLoop.current()
4040
self.loop.add_callback(self._record_started)

jupyter_client/manager.py

+23-24
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ async def _async__launch_kernel(
283283
"""
284284
return launch_kernel(kernel_cmd, **kw)
285285

286-
_launch_kernel = _async__launch_kernel
286+
_launch_kernel = run_sync(_async__launch_kernel)
287287

288288
# Control socket used for polite kernel shutdown
289289

@@ -383,7 +383,7 @@ async def _async_start_kernel(self, **kw):
383383
self.kernel = await self._async__launch_kernel(kernel_cmd, **kw)
384384
self.post_start_kernel(**kw)
385385

386-
start_kernel = _async_start_kernel
386+
start_kernel = run_sync(_async_start_kernel)
387387

388388
def request_shutdown(
389389
self,
@@ -433,7 +433,7 @@ async def _async_finish_shutdown(
433433
self.kernel.wait()
434434
self.kernel = None
435435

436-
finish_shutdown = _async_finish_shutdown
436+
finish_shutdown = run_sync(_async_finish_shutdown)
437437

438438
def cleanup_resources(
439439
self,
@@ -517,7 +517,7 @@ async def _async_shutdown_kernel(
517517
else:
518518
self.cleanup_resources(restart=restart)
519519

520-
shutdown_kernel = _async_shutdown_kernel
520+
shutdown_kernel = run_sync(_async_shutdown_kernel)
521521

522522
async def _async_restart_kernel(
523523
self,
@@ -563,7 +563,7 @@ async def _async_restart_kernel(
563563
self._launch_args.update(kw)
564564
await self._async_start_kernel(**self._launch_args)
565565

566-
restart_kernel = _async_restart_kernel
566+
restart_kernel = run_sync(_async_restart_kernel)
567567

568568
@property
569569
def has_kernel(self) -> bool:
@@ -600,7 +600,7 @@ async def _async__send_kernel_sigterm(self) -> None:
600600
if e.errno != ESRCH:
601601
raise
602602

603-
_send_kernel_sigterm = _async__send_kernel_sigterm
603+
_send_kernel_sigterm = run_sync(_async__send_kernel_sigterm)
604604

605605
async def _async__kill_kernel(self) -> None:
606606
"""Kill the running kernel.
@@ -641,7 +641,7 @@ async def _async__kill_kernel(self) -> None:
641641
self.kernel.wait()
642642
self.kernel = None
643643

644-
_kill_kernel = _async__kill_kernel
644+
_kill_kernel = run_sync(_async__kill_kernel)
645645

646646
async def _async_interrupt_kernel(self) -> None:
647647
"""Interrupts the kernel by sending it a signal.
@@ -666,7 +666,7 @@ async def _async_interrupt_kernel(self) -> None:
666666
else:
667667
raise RuntimeError("Cannot interrupt kernel. No kernel is running!")
668668

669-
interrupt_kernel = _async_interrupt_kernel
669+
interrupt_kernel = run_sync(_async_interrupt_kernel)
670670

671671
async def _async_signal_kernel(
672672
self,
@@ -691,7 +691,7 @@ async def _async_signal_kernel(
691691
else:
692692
raise RuntimeError("Cannot signal kernel. No kernel is running!")
693693

694-
signal_kernel = _async_signal_kernel
694+
signal_kernel = run_sync(_async_signal_kernel)
695695

696696
async def _async_is_alive(self) -> bool:
697697
"""Is the kernel process still running?"""
@@ -704,7 +704,7 @@ async def _async_is_alive(self) -> bool:
704704
# we don't have a kernel
705705
return False
706706

707-
is_alive = _async_is_alive
707+
is_alive = run_sync(_async_is_alive)
708708

709709
async def _async_wait(
710710
self,
@@ -718,23 +718,22 @@ async def _async_wait(
718718
await asyncio.sleep(pollinterval)
719719

720720

721-
class BlockingKernelManager(KernelManager):
722-
_launch_kernel = run_sync(KernelManager._launch_kernel)
723-
start_kernel = run_sync(KernelManager.start_kernel)
724-
finish_shutdown = run_sync(KernelManager.finish_shutdown)
725-
shutdown_kernel = run_sync(KernelManager.shutdown_kernel)
726-
restart_kernel = run_sync(KernelManager.restart_kernel)
727-
_send_kernel_sigterm = run_sync(KernelManager._send_kernel_sigterm)
728-
_kill_kernel = run_sync(KernelManager._kill_kernel)
729-
interrupt_kernel = run_sync(KernelManager.interrupt_kernel)
730-
signal_kernel = run_sync(KernelManager.signal_kernel)
731-
is_alive = run_sync(KernelManager.is_alive)
732-
733721
class AsyncKernelManager(KernelManager):
734722
# the class to create with our `client` method
735723
client_class: DottedObjectName = DottedObjectName('jupyter_client.asynchronous.AsyncKernelClient')
736724
client_factory: Type = Type(klass='jupyter_client.asynchronous.AsyncKernelClient')
737725

726+
_launch_kernel = KernelManager._async__launch_kernel
727+
start_kernel = KernelManager._async_start_kernel
728+
finish_shutdown = KernelManager._async_finish_shutdown
729+
shutdown_kernel = KernelManager._async_shutdown_kernel
730+
restart_kernel = KernelManager._async_restart_kernel
731+
_send_kernel_sigterm = KernelManager._async__send_kernel_sigterm
732+
_kill_kernel = KernelManager._async__kill_kernel
733+
interrupt_kernel = KernelManager._async_interrupt_kernel
734+
signal_kernel = KernelManager._async_signal_kernel
735+
is_alive = KernelManager._async_is_alive
736+
738737

739738
KernelManagerABC.register(KernelManager)
740739

@@ -743,9 +742,9 @@ def start_new_kernel(
743742
startup_timeout: float =60,
744743
kernel_name: str = 'python',
745744
**kwargs
746-
) -> t.Tuple[BlockingKernelManager, KernelClient]:
745+
) -> t.Tuple[KernelManager, KernelClient]:
747746
"""Start a new kernel, and return its Manager and Client"""
748-
km = BlockingKernelManager(kernel_name=kernel_name)
747+
km = KernelManager(kernel_name=kernel_name)
749748
km.start_kernel(**kwargs)
750749
kc = km.client()
751750
kc.start_channels()

jupyter_client/tests/test_kernelmanager.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from async_generator import async_generator, yield_
1818
from traitlets.config.loader import Config
1919
from jupyter_core import paths
20-
from jupyter_client import BlockingKernelManager, AsyncKernelManager
20+
from jupyter_client import KernelManager, AsyncKernelManager
2121
from subprocess import PIPE
2222

2323
from ..manager import start_new_kernel, start_new_async_kernel
@@ -101,7 +101,7 @@ def start_kernel():
101101

102102
@pytest.fixture
103103
def km(config):
104-
km = BlockingKernelManager(config=config)
104+
km = KernelManager(config=config)
105105
return km
106106

107107

@@ -186,7 +186,7 @@ def test_lifecycle(self, km):
186186
km.restart_kernel(now=True)
187187
assert km.is_alive()
188188
km.interrupt_kernel()
189-
assert isinstance(km, BlockingKernelManager)
189+
assert isinstance(km, KernelManager)
190190
km.shutdown_kernel(now=True)
191191
assert km.context.closed
192192

@@ -275,7 +275,7 @@ def test_cleanup_context(self, km):
275275

276276
def test_no_cleanup_shared_context(self, zmq_context):
277277
"""kernel manager does not terminate shared context"""
278-
km = BlockingKernelManager(context=zmq_context)
278+
km = KernelManager(context=zmq_context)
279279
assert km.context == zmq_context
280280
assert km.context is not None
281281

@@ -349,7 +349,7 @@ def _prepare_kernel(self, km, startup_timeout=TIMEOUT, **kwargs):
349349
return kc
350350

351351
def _run_signaltest_lifecycle(self, config=None):
352-
km = BlockingKernelManager(config=config, kernel_name='signaltest')
352+
km = KernelManager(config=config, kernel_name='signaltest')
353353
kc = self._prepare_kernel(km, stdout=PIPE, stderr=PIPE)
354354

355355
def execute(cmd):

jupyter_client/tests/test_public_api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
def test_kms():
12-
for base in ("", "Blocking", "Async", "Multi"):
12+
for base in ("", "Async", "Multi"):
1313
KM = base + "KernelManager"
1414
assert KM in dir(jupyter_client)
1515

0 commit comments

Comments
 (0)