manager - starting, stopping, signalling — jupyter_client 5.1.0 documentation

# manager - starting, stopping, signalling

class `jupyter_client.` `KernelManager`(**kwargs)

  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).

  `start_kernel`(**kw)

    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).

  `kernel`

    Once the kernel has been started, this is the `subprocess.Popen` class for the kernel process.

  `is_alive`()

    Is the kernel process still running?

  `interrupt_kernel`()

    Interrupts the kernel by sending it a signal.

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

  `signal_kernel`(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.

  `client`(**kwargs)

    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`(now=False, restart=False)

    Attempts to stop the kernel process cleanly.

    This attempts to shutdown the kernels cleanly by:

    1. Sending it a shutdown message over the shell channel.
    2. 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`(now=False, newports=False, **kw)

    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)

  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 by `start_kernel()`

  `start_kernel`(kernel_name=None, **kwargs)

    Start a new kernel.

    The caller can pick a kernel_id by passing one in as a keyword arg, otherwise one will be picked using a uuid.

    The kernel ID for the newly started kernel is returned.

  `list_kernel_ids`()

    Return a list of the kernel ids of the active kernels.

  `get_kernel`(kernel_id)

    Get the single KernelManager object for a kernel by its uuid.

    Parameters: | kernel_id (uuid) – The id of the kernel.

  `remove_kernel`(kernel_id)

    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.

  `shutdown_all`(now=False)

    Shutdown all kernels.

## Utility functions

`jupyter_client.` `run_kernel`(**kwargs)

  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