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

A blocking in-process channel.

call_handlers(msg)#

Call the handlers for a message.

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

Bases: InProcessKernelClient

A blocking in-process kernel client.

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.

async wait_for_ready()#

Wait for kernel info reply on shell channel.

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

Bases: BlockingInProcessChannel

A blocking in-process stdin channel.

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

Flush the channel.

is_alive()#

Test if the channel 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()#

Start the channel.

stop()#

Stop the channel.

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()#

Test if the channel is alive.

is_beating()#

Test if the channel is beating.

pause()#

Pause the channel.

start()#

Start the channel.

stop()#

Stop the channel.

time_to_dead = 3.0#
unpause()#

Unpause the channel.

A client for in-process kernels.

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

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.

async comm_info(target_name=None)#

Request a dictionary of valid comms and their targets.

async complete(code, cursor_pos=None)#

Get code completion.

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.

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

Execute code on the client.

get_connection_info()#

Get the connection info for the client.

get_control_msg(block=True, timeout=None)#

Get a control message.

get_iopub_msg(block=True, timeout=None)#

Get an iopub message.

get_shell_msg(block=True, timeout=None)#

Get a shell message.

get_stdin_msg(block=True, timeout=None)#

Get a stdin message.

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.

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

Get code history.

input(string)#

Handle kernel input.

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

Get code inspection.

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.

async is_complete(code)#

Handle an is_complete request.

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

async 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)#

Handle shutdown.

start_channels(*args, **kwargs)#

Start the channels on the client.

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

An in-process interactive shell.

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

An in-process kernel.

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_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

async start(*, task_status=<anyio._core._tasks._IgnoredTaskStatus object>)#

Override registration of dispatchers for streams.

Return type:

None

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.

stop()#

A kernel manager for in-process kernels.

class ipykernel.inprocess.manager.InProcessKernelManager(*args, **kwargs)#

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

Get a client for the 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()#

Interrupt the kernel.

is_alive()#

Test if the kernel is alive.

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

async restart_kernel(now=False, newports=False, *, task_status=<anyio._core._tasks._IgnoredTaskStatus object>, **kw)#

Restart the kernel.

Return type:

None

shutdown_kernel()#

Shutdown the kernel.

signal_kernel(signum)#

Send a signal to the kernel.

async start_kernel(*, task_status=<anyio._core._tasks._IgnoredTaskStatus object>, **kwds)#

Start the kernel.

Return type:

None

class ipykernel.inprocess.session.Session(**kwargs)#

Bases: Session

deserialize(msg, content=True, copy=True)#

Unserialize a msg_list to a nested message dict.

This is roughly the inverse of serialize. The serialize/deserialize methods work with full message lists, whereas pack/unpack work with the individual message parts in the message list.

Parameters#

msg_listlist of bytes or Message objects

The list of message parts of the form [HMAC,p_header,p_parent, p_metadata,p_content,buffer1,buffer2,…].

contentbool (True)

Whether to unpack the content dict (True), or leave it packed (False).

copybool (True)

Whether msg_list contains bytes (True) or the non-copying Message objects in each place (False).

Returns#

msgdict

The nested message dict with top-level keys [header, parent_header, content, buffers]. The buffers are returned as memoryviews.

feed_identities(msg, copy=True)#

Split the identities from the rest of the message.

Feed until DELIM is reached, then return the prefix as idents and remainder as msg_list. This is easily broken by setting an IDENT to DELIM, but that would be silly.

Parameters#

msg_lista list of Message or bytes objects

The message to be split.

copybool

flag determining whether the arguments are bytes or Messages

Returns#

(idents, msg_list)two lists

idents will always be a list of bytes, each of which is a ZMQ identity. msg_list will be a list of bytes or zmq.Messages of the form [HMAC,p_header,p_parent,p_content,buffer1,buffer2,…] and should be unpackable/unserializable via self.deserialize at this point.

async recv(socket, copy=True)#

Receive and unpack a message.

Parameters#

socketZMQStream or Socket

The socket or stream to use in receiving.

Returns#

[idents], msg

[idents] is a list of idents and msg is a nested message dict of same format as self.msg returns.

send(socket, msg_or_type, content=None, parent=None, ident=None, buffers=None, track=False, header=None, metadata=None)#

Build and send a message via stream or socket.

The message format used by this function internally is as follows:

[ident1,ident2,…,DELIM,HMAC,p_header,p_parent,p_content,

buffer1,buffer2,…]

The serialize/deserialize methods convert the nested message dict into this format.

Parameters#

streamzmq.Socket or ZMQStream

The socket-like object used to send the data.

msg_or_typestr or Message/dict

Normally, msg_or_type will be a msg_type unless a message is being sent more than once. If a header is supplied, this can be set to None and the msg_type will be pulled from the header.

contentdict or None

The content of the message (ignored if msg_or_type is a message).

headerdict or None

The header dict for the message (ignored if msg_to_type is a message).

parentMessage or dict or None

The parent or parent header describing the parent of this message (ignored if msg_or_type is a message).

identbytes or list of bytes

The zmq.IDENTITY routing path.

metadatadict or None

The metadata describing the message

bufferslist or None

The already-serialized buffers to be appended to the message.

trackbool

Whether to track. Only for use with Sockets, because ZMQStream objects cannot track messages.

Returns#

msgdict

The constructed message.

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

async get()#
async poll(timeout=0)#
put(msg)#
async recv_multipart(flags=0, copy=True, track=False)#

Recv a multipart message.

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

Send a multipart message.

Module contents#