Skip to main content

A concurrent python kernel for Jupyter supporting AnyIO, AsyncIO and Trio.

Project description

Async kernel

pypi downloads CI Ruff uv basedpyright - checked Built with Material for MkDocs codecov

logo-svg

Async kernel is a Python Jupyter kernel with fully configurable concurrent message handling. One major benefit of concurrent message handling is that iopub messages, such as those associated with widgets can pass freely whist an execute request is underway.

Highlights

Documentation

Installation

pip install async-kernel

Trio backend

To add a kernel spec for a trio backend.

pip install trio
async-kernel -a async-trio

See also: command line usage.

Asynchronous event loops

Async kernel uses Caller for concurrent message handling.

There are two callers:

  • Shell - runs in the MainThread handling user related requests[^non-main-thread].
  • Control - runs in a separate thread handling control related requests.

Messaging

Messages are received in a separate thread (per-channel) then handled in the associated thread (shell/control) concurrently according to the determined run mode.

Run mode

The run modes available are:

  • RunMode.directCaller.call_direct: Run the request in the scheduler.
  • RunMode.queueCaller.queue_call: Run the request in a queue dedicated to the subshell, handler & channel.
  • RunMode.taskCaller.call_soon: Run the request in a separate task.
  • RunMode.threadCaller.to_thread: Run the request in a separate worker thread.

These are the currently assigned run modes.

SocketID shell control
comm_close direct direct
comm_info_request direct direct
comm_msg queue queue
comm_open direct direct
complete_request thread thread
create_subshell_request None thread
debug_request None queue
delete_subshell_request None thread
execute_request queue queue
history_request thread thread
inspect_request thread thread
interrupt_request direct direct
is_complete_request thread thread
kernel_info_request direct direct
list_subshell_request None direct
shutdown_request None direct

Jupyter Kernel Subshells

Async kernel supports kernel subshells (JEP92). Each subshell provides a separate user_ns and shares the user_global_ns with the main shell.

Subshells are a useful means of providing separate namespaces and task management.

Subshells use the same callers as the main shell. This was a deliberate design choice with the advantage being that comm messages are always handled in the shell's thread (the main thread except when the shell is intentionally started in a different thread).

The active shell/subshell is controlled by setting a context variable. This is done by the kernel on a per-message basis. A context manager is also provided so that code can be executed in the context of a specific shell/subshell.

When a subshell is stopped its pending manager will cancel Pending (tasks) created in its context.

Kernel message handlers

No additional sockets are created for subshells.

Message handler methods are cached per channel and subshell ID, so when run mode is 'queue' (such as comm_msg), the message will be handled in a separate queue for the subshell/channel.

Further detail

Origin

Async kernel started as a fork of IPyKernel. Thank you to the original contributors of IPyKernel that made Async kernel possible.

[^uv-loop]: Uvloop is not a dependency of async-kernel but will be used if it has been installed.

[^non-main-thread]: The Shell can run in other threads with the associated limitations with regard to signalling and interrupts.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

async_kernel-0.11.2.tar.gz (286.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

async_kernel-0.11.2-py3-none-any.whl (94.4 kB view details)

Uploaded Python 3

File details

Details for the file async_kernel-0.11.2.tar.gz.

File metadata

  • Download URL: async_kernel-0.11.2.tar.gz
  • Upload date:
  • Size: 286.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for async_kernel-0.11.2.tar.gz
Algorithm Hash digest
SHA256 0eeae3fb281b0d360bfcb975d60daaa66fd4287e8f5805413db49790ae5acbad
MD5 e64ba1f6f123426fe64f8a3717d059a3
BLAKE2b-256 4c61c3c20d899bbc59f497b663e00149b95fd0be6955de75af5a935d0642df1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for async_kernel-0.11.2.tar.gz:

Publisher: publish-to-pypi.yml on fleming79/async-kernel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file async_kernel-0.11.2-py3-none-any.whl.

File metadata

  • Download URL: async_kernel-0.11.2-py3-none-any.whl
  • Upload date:
  • Size: 94.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for async_kernel-0.11.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b38021df0ca8f52ce51a10a7090613c57c9c2e4991e80a5ac8b0f90d4bbf4a13
MD5 245d0a3e5008e62d3d5d0200eb3ce48f
BLAKE2b-256 dbc8e7452eae1171a09d32be73241a8b46f2dbc062dd5d51ab4182a0efd82402

See more details on using hashes here.

Provenance

The following attestation bundles were made for async_kernel-0.11.2-py3-none-any.whl:

Publisher: publish-to-pypi.yml on fleming79/async-kernel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page