33
33
from .managerabc import (
34
34
KernelManagerABC
35
35
)
36
- from .util import run_sync
36
+ from .util import run_sync , ensure_async
37
37
38
38
class _ShutdownStatus (Enum ):
39
39
"""
@@ -272,7 +272,7 @@ def from_ns(match):
272
272
273
273
return [pat .sub (from_ns , arg ) for arg in cmd ]
274
274
275
- async def _async__launch_kernel (
275
+ async def _async_launch_kernel (
276
276
self ,
277
277
kernel_cmd : t .List [str ],
278
278
** kw
@@ -283,7 +283,7 @@ async def _async__launch_kernel(
283
283
"""
284
284
return launch_kernel (kernel_cmd , ** kw )
285
285
286
- _launch_kernel = run_sync (_async__launch_kernel )
286
+ _launch_kernel = run_sync (_async_launch_kernel )
287
287
288
288
# Control socket used for polite kernel shutdown
289
289
@@ -380,7 +380,7 @@ async def _async_start_kernel(self, **kw):
380
380
381
381
# launch the kernel subprocess
382
382
self .log .debug ("Starting kernel: %s" , kernel_cmd )
383
- self .kernel = await self ._async__launch_kernel (kernel_cmd , ** kw )
383
+ self .kernel = await ensure_async ( self ._launch_kernel (kernel_cmd , ** kw ) )
384
384
self .post_start_kernel (** kw )
385
385
386
386
start_kernel = run_sync (_async_start_kernel )
@@ -417,7 +417,7 @@ async def _async_finish_shutdown(
417
417
except asyncio .TimeoutError :
418
418
self .log .debug ("Kernel is taking too long to finish, terminating" )
419
419
self ._shutdown_status = _ShutdownStatus .SigtermRequest
420
- await self ._async__send_kernel_sigterm ()
420
+ await self ._async_send_kernel_sigterm ()
421
421
422
422
try :
423
423
await asyncio .wait_for (
@@ -426,7 +426,7 @@ async def _async_finish_shutdown(
426
426
except asyncio .TimeoutError :
427
427
self .log .debug ("Kernel is taking too long to finish, killing" )
428
428
self ._shutdown_status = _ShutdownStatus .SigkillRequest
429
- await self ._async__kill_kernel ( )
429
+ await ensure_async ( self ._kill_kernel () )
430
430
else :
431
431
# Process is no longer alive, wait and clear
432
432
if self .kernel is not None :
@@ -485,16 +485,16 @@ async def _async_shutdown_kernel(
485
485
# Stop monitoring for restarting while we shutdown.
486
486
self .stop_restarter ()
487
487
488
- await self ._async_interrupt_kernel ( )
488
+ await ensure_async ( self .interrupt_kernel () )
489
489
490
490
if now :
491
- await self ._async__kill_kernel ( )
491
+ await ensure_async ( self ._kill_kernel () )
492
492
else :
493
493
self .request_shutdown (restart = restart )
494
494
# Don't send any additional kernel kill messages immediately, to give
495
495
# the kernel a chance to properly execute shutdown actions. Wait for at
496
496
# most 1s, checking every 0.1s.
497
- await self ._async_finish_shutdown ( )
497
+ await ensure_async ( self .finish_shutdown () )
498
498
499
499
# In 6.1.5, a new method, cleanup_resources(), was introduced to address
500
500
# a leak issue (https://github.com/jupyter/jupyter_client/pull/548) and
@@ -554,14 +554,14 @@ async def _async_restart_kernel(
554
554
"No previous call to 'start_kernel'." )
555
555
else :
556
556
# Stop currently running kernel.
557
- await self ._async_shutdown_kernel (now = now , restart = True )
557
+ await ensure_async ( self .shutdown_kernel (now = now , restart = True ) )
558
558
559
559
if newports :
560
560
self .cleanup_random_ports ()
561
561
562
562
# Start new kernel.
563
563
self ._launch_args .update (kw )
564
- await self ._async_start_kernel (** self ._launch_args )
564
+ await ensure_async ( self .start_kernel (** self ._launch_args ) )
565
565
566
566
restart_kernel = run_sync (_async_restart_kernel )
567
567
@@ -570,7 +570,7 @@ def has_kernel(self) -> bool:
570
570
"""Has a kernel been started that we are managing."""
571
571
return self .kernel is not None
572
572
573
- async def _async__send_kernel_sigterm (self ) -> None :
573
+ async def _async_send_kernel_sigterm (self ) -> None :
574
574
"""similar to _kill_kernel, but with sigterm (not sigkill), but do not block"""
575
575
if self .has_kernel :
576
576
# Signal the kernel to terminate (sends SIGTERM on Unix and
@@ -600,9 +600,9 @@ async def _async__send_kernel_sigterm(self) -> None:
600
600
if e .errno != ESRCH :
601
601
raise
602
602
603
- _send_kernel_sigterm = run_sync (_async__send_kernel_sigterm )
603
+ _send_kernel_sigterm = run_sync (_async_send_kernel_sigterm )
604
604
605
- async def _async__kill_kernel (self ) -> None :
605
+ async def _async_kill_kernel (self ) -> None :
606
606
"""Kill the running kernel.
607
607
608
608
This is a private method, callers should use shutdown_kernel(now=True).
@@ -641,7 +641,7 @@ async def _async__kill_kernel(self) -> None:
641
641
self .kernel .wait ()
642
642
self .kernel = None
643
643
644
- _kill_kernel = run_sync (_async__kill_kernel )
644
+ _kill_kernel = run_sync (_async_kill_kernel )
645
645
646
646
async def _async_interrupt_kernel (self ) -> None :
647
647
"""Interrupts the kernel by sending it a signal.
@@ -723,13 +723,13 @@ class AsyncKernelManager(KernelManager):
723
723
client_class : DottedObjectName = DottedObjectName ('jupyter_client.asynchronous.AsyncKernelClient' )
724
724
client_factory : Type = Type (klass = 'jupyter_client.asynchronous.AsyncKernelClient' )
725
725
726
- _launch_kernel = KernelManager ._async__launch_kernel
726
+ _launch_kernel = KernelManager ._async_launch_kernel
727
727
start_kernel = KernelManager ._async_start_kernel
728
728
finish_shutdown = KernelManager ._async_finish_shutdown
729
729
shutdown_kernel = KernelManager ._async_shutdown_kernel
730
730
restart_kernel = KernelManager ._async_restart_kernel
731
- _send_kernel_sigterm = KernelManager ._async__send_kernel_sigterm
732
- _kill_kernel = KernelManager ._async__kill_kernel
731
+ _send_kernel_sigterm = KernelManager ._async_send_kernel_sigterm
732
+ _kill_kernel = KernelManager ._async_kill_kernel
733
733
interrupt_kernel = KernelManager ._async_interrupt_kernel
734
734
signal_kernel = KernelManager ._async_signal_kernel
735
735
is_alive = KernelManager ._async_is_alive
0 commit comments