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 an IPython kernel for Jupyter that provides concurrent message handling via an asynchronous backend (asyncio or trio).

The kernel provides two external interfaces:

  1. Direct ZMQ socket messaging via a configuration file and kernel spec - (Jupyter, VScode, etc).
  2. An experimental callback style interface (Jupyterlite).

Documentation

Highlights

[^1]: A gui (host) enabled kernel runs a gui event loop with the asynchronous backend running as guest. The host must be set before the kernel is started. This was a deliberate design choice to to ensure good performance and reliability.

[^2]: It is also possible to use a caller to run a gui event loop in a separate thread (with a backend running as a guest) if the gui allows it (qt will only run in the main thread). Also note that pyplot will only permit one interactive gui library in a process.

[^3]: The asyncio implementation of start_guest_run was written by the author of aiologic and provided as a gist.

[^4]: trio's start_guest_run.

Prevent asynchronous deadlocks

The standard (synchronous) kernel implementation processes messages sequentially irrespective of the message type. The problem being that long running execute requests will make the kernel non-responsive. Another problem exists when an asynchronous execute request awaits a result that is delivered via a kernel message - this will cause a deadlock because the message will be stuck in the queue behind theblocking execute request[^5].

Async kernel handles messages according to the channel, message type and subshell id. So widget com message will get processed in a separate queue to an execute request. Further detail is given in the concurrency notebook, a Jupyterlite version is available here.

[^5]: Ipykernel solves this issue specifically for widgets by using the concept of 'widget coms over subshells'. Widget messages arrive in a different thread which on occasion can cause unexpected behaviour, especially when using asynchronous libraries.

Installation

pip install async-kernel

Kernel specs

A kernel spec with the name 'async' is added when async kernel is installed.

Kernel specs can be added/removed via the command line.

The kernel is configured via the interface with the options:

  • name
  • display_name
  • Parameters on the kernel including:
    • interface.backend
    • interface.backend_options
    • interface.loop
    • interface.loop_options
    • shell.timeout

Backends

The backend set on the interface is the asynchronous library the kernel uses for message handling. It is also the asynchronous library directly available when executing code in cells or via a console[^4].

[^4]: Irrespective of the configured backend, functions/coroutines can be executed using a specific backend with the method call_using_backend.

Example - overwrite the 'async' kernel spec to use a trio backend

pip install trio
async-kernel -a async --interface.backend=trio

Gui event loop

The kernel can be started with a gui event loop as the host and the backend running as a guest.

asyncio backend

# tk
async-kernel -a async-tk --interface.loop=tk

# qt
pip install PySide6-Essentials
async-kernel -a async-qt --interface.loop=qt

trio backend

pip install trio
# tk
async-kernel -a async-tk --interface.loop=tk --interface.backend=trio

# qt
pip install PySide6-Essentials
async-kernel -a async-qt --interface.loop=qt --interface.backend=trio

For further detail about kernel spec customisation see command line and kernel configuration.

Origin

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

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.12.4.tar.gz (305.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.12.4-py3-none-any.whl (107.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: async_kernel-0.12.4.tar.gz
  • Upload date:
  • Size: 305.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.12.4.tar.gz
Algorithm Hash digest
SHA256 64f725e755ba5adee04cf29624fa69892dd79db1aa417fce7fa2c5c66e8e9ee2
MD5 917d0ed35f4bf679ded36344facb4a7c
BLAKE2b-256 701d65810b095cd11537cff060864891376944c6706f7bffb222112f2b344c94

See more details on using hashes here.

Provenance

The following attestation bundles were made for async_kernel-0.12.4.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.12.4-py3-none-any.whl.

File metadata

  • Download URL: async_kernel-0.12.4-py3-none-any.whl
  • Upload date:
  • Size: 107.9 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.12.4-py3-none-any.whl
Algorithm Hash digest
SHA256 bf01e901be9ae39d45a600ed5969cc3be08347dbad1d2d688d2f52f6fdf4a492
MD5 8e7af1c78b4e1c7ce619a64e4216b96b
BLAKE2b-256 88c753a4132ece6f6dbdfc395b1e6bfe0680eb18960c9af6f454641d398b4b1d

See more details on using hashes here.

Provenance

The following attestation bundles were made for async_kernel-0.12.4-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