Kernel Manager

The Kernel Manager API is used to manage a kernel’s lifecycle. It does not provide communication support between the application and the kernel itself. Any third-parties implementing their own KernelProvider would likely implement their own KernelManager derived from the KernelManagerABC abstract base class. However, those providers using Popen to launch local kernels can use KernelManager directly.

class jupyter_kernel_mgmt.managerabc.KernelManagerABC

Abstract base class from which all KernelManager classes are derived.

kernel_id

The id associated with the kernel.

abstract async is_alive()

Check whether the kernel is currently alive (e.g. the process exists)

abstract async wait()

Wait for the kernel process to exit.

Returns True if the kernel is still alive after waiting, False if it exited (like is_alive()).

abstract async signal(signum)

Send a signal to the kernel.

abstract async interrupt()

Interrupt the kernel by sending it a signal or similar event

Kernels can request to get interrupts as messages rather than signals. The manager is not expected to handle this. KernelClient.interrupt() should send an interrupt_request or call this method as appropriate.

abstract async kill()

Forcibly terminate the kernel.

This method may be used to dispose of a kernel that won’t shut down. Working kernels should usually be shut down by sending shutdown_request from a client and giving it some time to clean up.

async cleanup()

Clean up any resources, such as files created by the manager.

class jupyter_kernel_mgmt.subproc.manager.KernelManager(popen, files_to_cleanup=None, win_interrupt_evt=None)

Manages a single kernel in a subprocess on this host.

Parameters
  • popen (subprocess.Popen or asyncio.subprocess.Process) – The process with the started kernel. Windows will use Popen (by default), while non-Windows will use asyncio’s Process.

  • files_to_cleanup (list of paths, optional) – Files to be cleaned up after terminating this kernel.

  • win_interrupt_evt – On Windows, a handle to be used to interrupt the kernel. Not used on other platforms.

async cleanup()

Clean up resources when the kernel is shut down

async interrupt()

Interrupts the kernel by sending it a signal.

Unlike signal_kernel, this operation is well supported on all platforms.

Kernels may ask for interrupts to be delivered by a message rather than a signal. This method does not handle that. Use KernelClient.interrupt to send a message or a signal as appropriate.

async is_alive()

Is the kernel process still running?

async kill()

Kill the running kernel.

async signal(signum)

Sends a signal to the process group of the kernel (this usually includes the kernel and any subprocesses spawned by the kernel).

Note that since only SIGTERM is supported on Windows, this function is only useful on Unix systems.

async wait()

Wait for kernel to terminate