Skip to content

Typing

async_kernel.typing

Classes:

ExecuteContent

Ref. see also: Message

Attributes:

allow_stdin instance-attribute

allow_stdin: bool

code instance-attribute

code: str

The code to execute.

silent instance-attribute

silent: bool

stop_on_error instance-attribute

stop_on_error: bool

store_history instance-attribute

store_history: bool

user_expressions instance-attribute

user_expressions: dict[str, str]

Job

An async_kernel.typing.Message bundled with sockit_id, socket and ident.

Attributes:

ident instance-attribute

ident: bytes | list[bytes]

msg instance-attribute

msg: Message[T]

received_time instance-attribute

received_time: float

The time the message was received.

run_mode instance-attribute

run_mode: RunMode

The run mode.

socket instance-attribute

socket: Socket

socket_id instance-attribute

socket_id: Literal[control, shell]

KernelConcurrencyMode

Attributes:

blocking class-attribute instance-attribute

blocking = 'blocking'

All handlers are run with the blocking.

default class-attribute instance-attribute

default = 'default'

The default concurrency mode

Message

A message.

Attributes:

buffers instance-attribute

buffers: list[bytearray | bytes]

content instance-attribute

content: T | Content

ref

See also:

header instance-attribute

header: MsgHeader

ref

metadata instance-attribute

metadata: Mapping[MetadataKeys | str, Any]

ref

parent_header instance-attribute

parent_header: MsgHeader

ref

MetadataKeys

This is an enum of keys for metadata in kernel messages that are used in async_kernel.

Note

Metadata can be edited in Jupyter lab "Advanced tools" and Tags can be added using "common tools" in the right side bar.

Attributes:

suppress_error_message class-attribute instance-attribute

suppress_error_message = 'suppress-error-message'

A message to print when the error has been suppressed using async_kernel.typing.Tags.suppress_error.

Note

The default message is '⚠'.

tags class-attribute instance-attribute

tags = 'tags'

The tags metadata key corresponds to is a list of strings.

The list can be edited by the user in a notebook. see also: Tags.

timeout class-attribute instance-attribute

timeout = 'timeout'

The timeout metadata key is used to specify a timeout for execution of the code.

The value should be a floating point value of the timeout in seconds.

MsgHeader

A message header.

Attributes:

date instance-attribute

date: str

msg_id instance-attribute

msg_id: str

msg_type instance-attribute

msg_type: MsgType

session instance-attribute

session: str

username instance-attribute

username: str

version instance-attribute

version: str

MsgType

An enumeration of Message msg_type for shell and control messages.

Some message types are on the control channel only.

Attributes:

comm_close class-attribute instance-attribute

comm_close = 'comm_close'

comm_info_request class-attribute instance-attribute

comm_info_request = 'comm_info_request'

comm_msg class-attribute instance-attribute

comm_msg = 'comm_msg'

comm_open class-attribute instance-attribute

comm_open = 'comm_open'

complete_request class-attribute instance-attribute

complete_request = 'complete_request'

debug_request class-attribute instance-attribute

debug_request = 'debug_request'

async_kernel.Kernel.debug_request (control channel only)

execute_request class-attribute instance-attribute

execute_request = 'execute_request'

history_request class-attribute instance-attribute

history_request = 'history_request'

inspect_request class-attribute instance-attribute

inspect_request = 'inspect_request'

interrupt_request class-attribute instance-attribute

interrupt_request = 'interrupt_request'

async_kernel.Kernel.interrupt_request (control channel only)

is_complete_request class-attribute instance-attribute

is_complete_request = 'is_complete_request'

kernel_info_request class-attribute instance-attribute

kernel_info_request = 'kernel_info_request'

shutdown_request class-attribute instance-attribute

shutdown_request = 'shutdown_request'

async_kernel.Kernel.shutdown_request (control channel only)

RunMode

An Enum of the kernel run modes available for altering how message requests are run.

String match options

Each of these options will give a match.

  • <value>
  • <##value>
  • 'RunMode.<value>.

special usage

Run mode can be used in execute requests. Add it at the top line (or use the string equivalent "##") of a code cell.

Methods:

  • get_mode

    Get a RunMode from the code if it is found.

Attributes:

  • blocking

    Run the handler directly as soon as it is received.

  • queue

    The message for the handler is run sequentially with other messages that are queued.

  • task

    The message for the handler are run concurrently in task (starting immediately).

  • thread

    Messages for the handler are run concurrently in a thread (starting immediately).

blocking class-attribute instance-attribute

blocking = 'blocking'

Run the handler directly as soon as it is received.

Warning

This mode blocks the message loop.

Use this for short running messages that should be processed as soon as it is received.

queue class-attribute instance-attribute

queue = 'queue'

The message for the handler is run sequentially with other messages that are queued.

task class-attribute instance-attribute

task = 'task'

The message for the handler are run concurrently in task (starting immediately).

thread class-attribute instance-attribute

thread = 'thread'

Messages for the handler are run concurrently in a thread (starting immediately).

get_mode classmethod

get_mode(code: str) -> RunMode | None

Get a RunMode from the code if it is found.

Source code in src/async_kernel/typing.py
84
85
86
87
88
89
90
91
92
93
@classmethod
def get_mode(cls, code: str) -> RunMode | None:
    "Get a RunMode from the code if it is found."
    try:
        if (code := code.strip().split("\n")[0].strip()).startswith("##"):
            return RunMode(code.removeprefix("##"))
        if code.startswith("RunMode."):
            return RunMode(code.removeprefix("RunMode."))
    except ValueError:
        return None

SocketID

Mapping of Kernel.port_<id> for sockets. Ref.

Attributes:

control class-attribute instance-attribute

control = 'control'

heartbeat class-attribute instance-attribute

heartbeat = 'hb'

iopub class-attribute instance-attribute

iopub = 'iopub'

shell class-attribute instance-attribute

shell = 'shell'

stdin class-attribute instance-attribute

stdin = 'stdin'

Tags

Tags recognised by the kernel.

Info

Tags are can be added per cell.

Attributes:

  • suppress_error

    Suppress exceptions that occur during execution of the code cell.

suppress_error class-attribute instance-attribute

suppress_error = 'suppress-error'

Suppress exceptions that occur during execution of the code cell.

Warning

The code block will return as 'ok' and there will be no message recorded.