Warning

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

Module: kernel.client

Base class to manage the interaction with a running kernel

1 Class

class IPython.kernel.client.KernelClient(**kwargs)

Bases: IPython.config.configurable.LoggingConfigurable, IPython.kernel.connect.ConnectionFileMixin

Communicates with a single kernel on any host via zmq channels.

There are four channels associated with each kernel:

  • shell: for request/reply calls to the kernel.
  • iopub: for the kernel to publish results to frontends.
  • hb: for monitoring the kernel’s heartbeat.
  • stdin: for frontends to reply to raw_input calls in the kernel.

The methods of the channels are exposed as methods of the client itself (KernelClient.execute, complete, history, etc.). See the channels themselves for documentation of these methods.

channels_running

Are any of the channels created and running?

get_iopub_msg(*args, **kwargs)

Get a message from the iopub channel

get_shell_msg(*args, **kwargs)

Get a message from the shell channel

get_stdin_msg(*args, **kwargs)

Get a message from the stdin channel

hb_channel

Get the hb channel object for this kernel.

iopub_channel

Get the iopub channel object for this kernel.

is_alive()

Is the kernel process still running?

shell_channel

Get the shell channel object for this kernel.

start_channels(shell=True, iopub=True, stdin=True, hb=True)

Starts the channels for this kernel.

This will create the channels if they do not exist and then start them (their activity runs in a thread). If port numbers of 0 are being used (random ports) then you must first call start_kernel(). If the channels have been stopped and you call this, RuntimeError will be raised.

stdin_channel

Get the stdin channel object for this kernel.

stop_channels()

Stops all the running channels for this kernel.

This stops their event loops and joins their threads.