ipykernel.inprocess package#

Submodules#

Implements a fully blocking kernel client.

Useful for test suites and blocking terminal interfaces.

class ipykernel.inprocess.blocking.BlockingInProcessChannel(*args, **kwds)#

Bases: InProcessChannel

call_handlers(msg)#

This method is called in the main thread when a message arrives.

Subclasses should override this method to handle incoming messages.

get_msg(block=True, timeout=None)#

Gets a message if there is one that is ready.

get_msgs()#

Get all messages that are currently ready.

msg_ready()#

Is there a message that has been received?

class ipykernel.inprocess.blocking.BlockingInProcessKernelClient(**kwargs: Any)#

Bases: InProcessKernelClient

iopub_channel_class#

A trait whose value must be a subclass of a specified class.

shell_channel_class#

A trait whose value must be a subclass of a specified class.

stdin_channel_class#

A trait whose value must be a subclass of a specified class.

wait_for_ready()#
class ipykernel.inprocess.blocking.BlockingInProcessStdInChannel(*args, **kwds)#

Bases: BlockingInProcessChannel

call_handlers(msg)#

Overridden for the in-process channel.

This methods simply calls raw_input directly.

A kernel client for in-process kernels.

class ipykernel.inprocess.channels.InProcessChannel(client=None)#

Bases: object

Base class for in-process channels.

call_handlers(msg)#

This method is called in the main thread when a message arrives.

Subclasses should override this method to handle incoming messages.

call_handlers_later(*args, **kwds)#

Call the message handlers later.

The default implementation just calls the handlers immediately, but this method exists so that GUI toolkits can defer calling the handlers until after the event loop has run, as expected by GUI frontends.

flush(timeout=1.0)#
is_alive()#
process_events()#

Process any pending GUI events.

This method will be never be called from a frontend without an event loop (e.g., a terminal frontend).

proxy_methods: List[object] = []#
start()#
stop()#
class ipykernel.inprocess.channels.InProcessHBChannel(client=None)#

Bases: object

A dummy heartbeat channel interface for in-process kernels.

Normally we use the heartbeat to check that the kernel process is alive. When the kernel is in-process, that doesn’t make sense, but clients still expect this interface.

is_alive()#
is_beating()#
pause()#
start()#
stop()#
time_to_dead = 3.0#
unpause()#

A client for in-process kernels.

class ipykernel.inprocess.client.InProcessKernelClient(**kwargs: Any)#

Bases: KernelClient

A client for an in-process kernel.

This class implements the interface of jupyter_client.clientabc.KernelClientABC and allows (asynchronous) frontends to be used seamlessly with an in-process kernel.

See jupyter_client.client.KernelClient for docstrings.

comm_info(target_name=None)#

Request a dictionary of valid comms and their targets.

complete(code, cursor_pos=None)#

Tab complete text in the kernel’s namespace.

Parameters#

codestr

The context in which completion is requested. Can be anything between a variable name and an entire cell.

cursor_posint, optional

The position of the cursor in the block of code where the completion was requested. Default: len(code)

Returns#

The msg_id of the message sent.

property control_channel#

Get the control channel object for this kernel.

control_channel_class#

A trait whose value must be a subclass of a specified class.

execute(code, silent=False, store_history=True, user_expressions=None, allow_stdin=None)#

Execute code in the kernel.

Parameters#

codestr

A string of code in the kernel’s language.

silentbool, optional (default False)

If set, the kernel will execute the code as quietly possible, and will force store_history to be False.

store_historybool, optional (default True)

If set, the kernel will store command history. This is forced to be False if silent is True.

user_expressionsdict, optional

A dict mapping names to expressions to be evaluated in the user’s dict. The expression values are returned as strings formatted using repr().

allow_stdinbool, optional (default self.allow_stdin)

Flag for whether the kernel can send stdin requests to frontends.

Some frontends (e.g. the Notebook) do not support stdin requests. If raw_input is called from code executed from such a frontend, a StdinNotImplementedError will be raised.

stop_on_error: bool, optional (default True)

Flag whether to abort the execution queue, if an exception is encountered.

Returns#

The msg_id of the message sent.

get_connection_info()#

Return the connection info as a dict

Parameters#

sessionbool [default: False]

If True, return our session object will be included in the connection info. If False (default), the configuration parameters of our session object will be included, rather than the session object itself.

Returns#

connect_infodict

dictionary of connection information.

get_control_msg(block=True, timeout=None)#
get_iopub_msg(block=True, timeout=None)#
get_shell_msg(block=True, timeout=None)#
get_stdin_msg(block=True, timeout=None)#
property hb_channel#

Get the hb channel object for this kernel.

hb_channel_class#

A trait whose value must be a subclass of a specified class.

history(raw=True, output=False, hist_access_type='range', **kwds)#

Get entries from the kernel’s history list.

Parameters#

rawbool

If True, return the raw input.

outputbool

If True, then return the output as well.

hist_access_typestr
‘range’ (fill in session, start and stop params), ‘tail’ (fill in n)

or ‘search’ (fill in pattern param).

sessionint

For a range request, the session from which to get lines. Session numbers are positive integers; negative ones count back from the current session.

startint

The first line number of a history range.

stopint

The final (excluded) line number of a history range.

nint

The number of lines of history to get for a tail request.

patternstr

The glob-syntax pattern for a search request.

Returns#

The ID of the message sent.

input(string)#

Send a string of raw input to the kernel.

This should only be called in response to the kernel sending an input_request message on the stdin channel.

inspect(code, cursor_pos=None, detail_level=0)#

Get metadata information about an object in the kernel’s namespace.

It is up to the kernel to determine the appropriate object to inspect.

Parameters#

codestr

The context in which info is requested. Can be anything between a variable name and an entire cell.

cursor_posint, optional

The position of the cursor in the block of code where the info was requested. Default: len(code)

detail_levelint, optional

The level of detail for the introspection (0-2)

Returns#

The msg_id of the message sent.

property iopub_channel#

Get the iopub channel object for this kernel.

iopub_channel_class#

A trait whose value must be a subclass of a specified class.

is_complete(code)#

Ask the kernel whether some code is complete and ready to execute.

kernel#

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

Subclasses can declare default classes by overriding the klass attribute

kernel_info()#

Request kernel info.

property shell_channel#

Get the shell channel object for this kernel.

shell_channel_class#

A trait whose value must be a subclass of a specified class.

shutdown(restart=False)#

Request an immediate kernel shutdown on the control channel.

Upon receipt of the (empty) reply, client code can safely assume that the kernel has shut down and it’s safe to forcefully terminate it if it’s still alive.

The kernel will send the reply via a function registered with Python’s atexit module, ensuring it’s truly done as the kernel is done with all normal operation.

Returns#

The msg_id of the message sent

start_channels(*args, **kwargs)#

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.

property stdin_channel#

Get the stdin channel object for this kernel.

stdin_channel_class#

A trait whose value must be a subclass of a specified class.

Shared constants.

An in-process kernel

class ipykernel.inprocess.ipkernel.InProcessInteractiveShell(**kwargs: Any)#

Bases: ZMQInteractiveShell

enable_gui(gui=None)#

Enable GUI integration for the kernel.

enable_matplotlib(gui=None)#

Enable matplotlib integration for the kernel.

enable_pylab(gui=None, import_all=True, welcome_message=False)#

Activate pylab support at runtime.

kernel: InProcessKernel#

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

Subclasses can declare default classes by overriding the klass attribute

class ipykernel.inprocess.ipkernel.InProcessKernel(**kwargs: Any)#

Bases: IPythonKernel

async execute_request(stream, ident, parent)#

Override for temporary IO redirection.

frontends#

An instance of a Python list.

gui#

An enum whose value must be in a given sequence.

iopub_socket: BackgroundSocket#

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

Subclasses can declare default classes by overriding the klass attribute

iopub_thread: IOPubThread#

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

Subclasses can declare default classes by overriding the klass attribute

raw_input_str#

A trait which allows any value.

shell_class#

A trait whose value must be a subclass of a specified class.

shell_stream#

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

Subclasses can declare default classes by overriding the klass attribute

start()#

Override registration of dispatchers for streams.

stderr#

A trait which allows any value.

stdin_socket#

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

Subclasses can declare default classes by overriding the klass attribute

stdout#

A trait which allows any value.

A kernel manager for in-process kernels.

class ipykernel.inprocess.manager.InProcessKernelManager(**kwargs: Any)#

Bases: KernelManager

A manager for an in-process kernel.

This class implements the interface of jupyter_client.kernelmanagerabc.KernelManagerABC and allows (asynchronous) frontends to be used seamlessly with an in-process kernel.

See jupyter_client.kernelmanager.KernelManager for docstrings.

client(**kwargs)#

Create a client configured to connect to our kernel

client_class: DottedObjectName#

A string holding a valid dotted object name in Python, such as A.b3._c

property has_kernel#

Has a kernel process been started that we are actively managing.

interrupt_kernel()#

Interrupts the kernel by sending it a signal.

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

is_alive()#

Is the kernel process still running?

kernel#

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

Subclasses can declare default classes by overriding the klass attribute

restart_kernel(now=False, **kwds)#

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

Parameters#

nowbool, 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.

newportsbool, 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.

**kwoptional

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

shutdown_kernel()#

Attempts to stop the kernel process cleanly.

This attempts to shutdown the kernels cleanly by:

  1. Sending it a shutdown message over the control channel.

  2. If that fails, the kernel is shutdown forcibly by sending it a signal.

Parameters#

nowbool

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.

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.

start_kernel(**kwds)#

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#

**kwoptional

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

Defines a dummy socket implementing (part of) the zmq.Socket interface.

class ipykernel.inprocess.socket.DummySocket(**kwargs: Any)#

Bases: HasTraits

A dummy socket implementing (part of) the zmq.Socket interface.

context#

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

Subclasses can declare default classes by overriding the klass attribute

flush(timeout=1.0)#

no-op to comply with stream API

message_sent#

An int trait.

queue#

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

Subclasses can declare default classes by overriding the klass attribute

recv_multipart(flags=0, copy=True, track=False)#
send_multipart(msg_parts, flags=0, copy=True, track=False)#

Module contents#