manager - starting, stopping, signalling¶
- class jupyter_client.KernelManager(**kwargs: Any)¶
Manages a single kernel in a subprocess on this host.
This version starts kernels with Popen.
- kernel_name¶
The name of the kernel to launch (see Kernel specs).
- provisioner: Optional[KernelProvisionerBase] = None¶
The kernel provisioner with which this
KernelManager
is communicating. This will generally be aLocalProvisioner
instance unless the kernelspec indicates otherwise.
- start_kernel(**kwargs)¶
Starts a kernel on this host in a separate process.
If random ports (port=0) are being used, this method must be called before the channels are created.
- Parameters
**kw (optional) – keyword arguments that are passed down to build the kernel_cmd and launching the kernel (e.g. Popen kwargs).
- is_alive(**kwargs)¶
Is the kernel process still running?
- interrupt_kernel(**kwargs)¶
Interrupts the kernel by sending it a signal.
Unlike
signal_kernel
, this operation is well supported on all platforms.
- signal_kernel(**kwargs)¶
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.
- client(**kwargs: Any) KernelClient ¶
Create a client configured to connect to our kernel
For the client API, see
jupyter_client.client
.
- blocking_client()¶
Make a blocking client connected to my kernel
- shutdown_kernel(**kwargs)¶
Attempts to stop the kernel process cleanly.
This attempts to shutdown the kernels cleanly by:
Sending it a shutdown message over the control channel.
If that fails, the kernel is shutdown forcibly by sending it a signal.
- Parameters
now (bool) – Should the kernel be forcible killed now. This skips the first, nice shutdown attempt.
restart (bool) – Will this kernel be restarted after it is shutdown. When this is True, connection files will not be cleaned up.
- restart_kernel(**kwargs)¶
Restarts a kernel with the arguments that were used to launch it.
- Parameters
now (bool, optional) –
If True, the kernel is forcefully restarted immediately, without having a chance to do any cleanup action. Otherwise the kernel is given 1s to clean up before a forceful restart is issued.
In all cases the kernel is restarted, the only difference is whether it is given a chance to perform a clean shutdown or not.
newports (bool, optional) – If the old kernel was launched with random ports, this flag decides whether the same ports and connection file will be used again. If False, the same ports and connection file are used. This is the default. If True, new random port numbers are chosen and a new connection file is written. It is still possible that the newly chosen random port numbers happen to be the same as the old ones.
**kw (optional) – Any options specified here will overwrite those used to launch the kernel.
multikernelmanager - controlling multiple kernels¶
- class jupyter_client.MultiKernelManager(**kwargs: Any)¶
A class for managing multiple kernels.
This exposes the same methods as
KernelManager
, but their first parameter is a kernel ID, a string identifying the kernel instance. Typically these are UUIDs picked bystart_kernel()
- start_kernel(**kwargs)¶
Start a new kernel.
The caller can pick a kernel_id by passing one in as a keyword arg, otherwise one will be generated using new_kernel_id().
The kernel ID for the newly started kernel is returned.
- list_kernel_ids() List[str] ¶
Return a list of the kernel ids of the active kernels.
- get_kernel(kernel_id: str) KernelManager ¶
Get the single KernelManager object for a kernel by its uuid.
- Parameters
kernel_id (uuid) – The id of the kernel.
- remove_kernel(kernel_id: str) KernelManager ¶
remove a kernel from our mapping.
Mainly so that a kernel can be removed if it is already dead, without having to call shutdown_kernel.
The kernel object is returned, or None if not found.
- shutdown_all(**kwargs)¶
Shutdown all kernels.
Utility functions¶
- jupyter_client.run_kernel(**kwargs: Any) Iterator[KernelClient] ¶
Context manager to create a kernel in a subprocess.
The kernel is shut down when the context exits.
- Returns
kernel_client
- Return type
connected KernelClient instance