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

Module: kernel.threaded

Defines a KernelClient that provides thread-safe sockets with async callbacks on message replies.

3 Classes

class IPython.kernel.threaded.ThreadedZMQSocketChannel(socket, session, loop)

Bases: object

A ZMQ socket invoking a callback in the ioloop

__init__(socket, session, loop)

Create a channel.


socket : zmq.Socket

The ZMQ socket to use.

session : session.Session

The session to use.


A pyzmq ioloop to connect the socket to using a ZMQStream


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

Subclasses should override this method to handle incoming messages. It is important to remember that this method is called in the thread so that some logic must be done to ensure that the application level handlers are called in the application thread.


Immediately processes all pending messages on this channel.

This is only used for the IOPub channel.

Callers should use this method to ensure that call_handlers() has been called for all messages that have been received on the 0MQ SUB socket of this channel.

This method is thread safe.


timeout : float, optional

The maximum amount of time to spend flushing, in seconds. The default is one second.


Subclasses should override this with a method processing any pending GUI events.


Queue a message to be sent from the IOLoop’s thread.


msg : message to send

This is threadsafe, as it uses IOLoop.add_callback to give the loop’s

thread control of the action.

class IPython.kernel.threaded.IOLoopThread(loop)

Bases: threading.Thread

Run a pyzmq ioloop in a thread to send and receive messages


Run my loop, ignoring EINTR events in the poller


Stop the channel’s event loop and join its thread.

This calls join() and returns when the thread terminates. RuntimeError will be raised if start() is called again.

class IPython.kernel.threaded.ThreadedKernelClient(**kwargs)

Bases: IPython.kernel.client.KernelClient

A KernelClient that provides thread-safe sockets with async callbacks on message replies.