Skip to main content
`Ctrl`+`K`

# jupyter_server.services.kernels.connection package

## Submodules

class jupyter_server.services.kernels.connection.abc.KernelWebsocketConnectionABC

  Bases: `ABC`

  This class defines a minimal interface that should be used to bridge the connection between Jupyter Server’s websocket API and a kernel’s ZMQ socket interface.

  abstractmethod async connect()

    Connect the kernel websocket to the kernel ZMQ connections

  abstractmethod async disconnect()

    Disconnect the kernel websocket from the kernel ZMQ connections

  abstractmethod handle_incoming_message(incoming_msg)

    Broker the incoming websocket message to the appropriate ZMQ channel.

    Return type:

      `None`

  abstractmethod handle_outgoing_message(stream, outgoing_msg)

    Broker outgoing ZMQ messages to the kernel websocket.

    Return type:

      `None`

  websocket_handler: `Any`

Kernel connection helpers.

class jupyter_server.services.kernels.connection.base.BaseKernelWebsocketConnection(**kwargs)

  Bases: `LoggingConfigurable`

  A configurable base class for connecting Kernel WebSockets to ZMQ sockets.

  async connect()

    Handle a connect.

  async disconnect()

    Handle a disconnect.

  handle_incoming_message(incoming_msg)

    Handle an incoming message.

    Return type:

      `None`

  handle_outgoing_message(stream, outgoing_msg)

    Handle an outgoing message.

    Return type:

      `None`

  property kernel_id

    The kernel id.

  kernel_info_timeout

    A float trait.

  property kernel_manager

    The kernel manager.

  kernel_ws_protocol

    None). If an empty string is passed, select the legacy protocol. If None, the selected protocol will depend on what the front-end supports (usually the most recent protocol supported by the back-end and the front-end).

    Type:

      Preferred kernel message protocol over websocket to use (default

  property multi_kernel_manager

    The multi kernel manager.

  session

    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

  property session_id

    The session id.

  websocket_handler

    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

jupyter_server.services.kernels.connection.base.deserialize_binary_message(bmsg)

  deserialize a message from a binary blog

  Header:

  4 bytes: number of msg parts (nbufs) as 32b int 4 * nbufs bytes: offset for each buffer as integer as 32b int

  Offsets are from the start of the buffer, including the header.

  Return type:

    message dictionary

jupyter_server.services.kernels.connection.base.deserialize_msg_from_ws_v1(ws_msg)

  Deserialize a message using the v1 protocol.

jupyter_server.services.kernels.connection.base.serialize_binary_message(msg)

  serialize a message as a binary blob

  Header:

  4 bytes: number of msg parts (nbufs) as 32b int 4 * nbufs bytes: offset for each buffer as integer as 32b int

  Offsets are from the start of the buffer, including the header.

  Return type:

    The message serialized to bytes.

jupyter_server.services.kernels.connection.base.serialize_msg_to_ws_v1(msg_or_list, channel, pack=None)

  Serialize a message using the v1 protocol.

An implementation of a kernel connection.

class jupyter_server.services.kernels.connection.channels.ZMQChannelsWebsocketConnection(**kwargs)

  Bases: `BaseKernelWebsocketConnection`

  A Jupyter Server Websocket Connection

  channels

    An instance of a Python dict.

    One or more traits can be passed to the constructor to validate the keys and/or values of the dict. If you need more detailed validation, you may use a custom validator method.

    Changed in version 5.0: Added key_trait for validating dict keys.

    Changed in version 5.0: Deprecated ambiguous `trait`, `traits` args in favor of `value_trait`, `per_key_traits`.

  close()

    Close the connection.

  async classmethod close_all()

    Tornado does not provide a way to close open sockets, so add one.

  connect()

    Handle a connection.

  create_stream()

    Create a stream.

  disconnect()

    Handle a disconnect.

  get_part(field, value, msg_list)

    Get a part of a message.

  handle_incoming_message(incoming_msg)

    Handle incoming messages from Websocket to ZMQ Sockets.

    Return type:

      `None`

  handle_outgoing_message(stream, outgoing_msg)

    Handle the outgoing messages from ZMQ sockets to Websocket.

    Return type:

      `None`

  iopub_data_rate_limit

    (bytes/sec) Maximum rate at which stream output can be sent on iopub before they are limited.

  iopub_msg_rate_limit

    (msgs/sec) Maximum rate at which messages can be sent on iopub before they are limited.

  kernel_info_channel

    A trait which allows any value.

  limit_rate

    True). If True, use iopub_msg_rate_limit, iopub_data_rate_limit and/or rate_limit_window to tune the rate.

    Type:

      Whether to limit the rate of IOPub messages (default

  nudge()

    Nudge the zmq connections with kernel_info_requests Returns a Future that will resolve when we have received a shell or control reply and at least one iopub message, ensuring that zmq subscriptions are established, sockets are fully connected, and kernel is responsive. Keeps retrying kernel_info_request until these are both received.

  on_kernel_restarted()

    Handle a kernel restart.

  on_restart_failed()

    Handle a kernel restart failure.

  async prepare()

    Prepare a kernel connection.

  rate_limit_window

    (sec) Time window used to check the message and data rate limits.

  request_kernel_info()

    send a request for kernel_info

  session_key

    A trait for unicode strings.

  property subprotocol

    The sub protocol.

  websocket_handler

    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

  property write_message

    Alias to the websocket handler’s write_message method.

  write_stderr(error_message, parent_header)

    Write a message to stderr.

## Module contents