This documentation is for an old version of IPython. You can find docs for newer versions here.

Module: kernel.manager

Base class to manage a running kernel

1 Class

class IPython.kernel.manager.KernelManager(**kwargs)

Bases: IPython.kernel.connect.ConnectionFileMixin

Manages a single kernel in a subprocess on this host.

This version starts kernels with Popen.

add_restart_callback(callback, event='restart')

register a callback to be called when a kernel is restarted


Clean up resources when the kernel is shut down


Create a client configured to connect to our kernel

finish_shutdown(waittime=1, pollinterval=0.1)

Wait for kernel shutdown, then kill process if it doesn’t shutdown.

This does not send shutdown requests - use request_shutdown() first.


replace templated args (e.g. {connection_file})


Has a kernel been started that we are managing.


Interrupts the kernel by sending it a signal.

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


Is the kernel process still running?

remove_restart_callback(callback, event='restart')

unregister a callback to be called when a kernel is restarted


Send a shutdown request via control channel

On Windows, this just kills kernels instead, because the shutdown messages don’t work.

restart_kernel(now=False, **kw)

Restarts a kernel with the arguments that were used to launch it.

If the old kernel was launched with random ports, the same ports will be used for the new kernel. The same connection file is used again.


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.

**kw : optional

Any options specified here will overwrite those used to launch the kernel.

shutdown_kernel(now=False, restart=False)

Attempts to the 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.

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.


Sends a signal to the kernel.

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


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.


**kw : optional

keyword arguments that are passed down to build the kernel_cmd and launching the kernel (e.g. Popen kwargs).

2 Functions

IPython.kernel.manager.start_new_kernel(startup_timeout=60, kernel_name='python', **kwargs)

Start a new kernel, and return its Manager and Client


Context manager to create a kernel in a subprocess.

The kernel is shut down when the context exits.

Returns:kernel_client: connected KernelClient instance