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 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, VS Code, etc).
  2. An experimental callback style interface (Jupyterlite).

Highlights

Avoid deadlocks

The standard (synchronous) kernel implementation processes messages sequentially irrespective of the message type. The problem being that long running execute requests 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 the blocking execute request4.

async-kernel handles messages according to the channel and message type. 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.

Example

Make a blocking call in a Jupyter lab notebook or console.

# Make the shell's thread busy
import time

time.sleep(1e6)

While the above is blocking (the kernel is busy).

dir()  # try code completion (tab) or view the docstring (shift tab)

Interrupt the kernel.

It also works for awaitables.

import ipywidgets as ipw
from aiologic import Event

b = ipw.Button(description="Click me")
event = Event()
b.on_click(lambda _: event.set())
display(b)
await event

Installation

pip install async-kernel

Kernelspecs

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

Kernel specs can be installed/uninstalled via the command line.

async-kernel install

# To install for a user
async-kernel install --user

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

Faster data serialization

orjson (a fast JSON library) is supported and will be used by default if it has been installed.

Free-threading support

async-kernel's Caller's are thread-local and it's methods are internally synchronised5.

Origin

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

  1. A gui (host) enabled kernel interface starts a gui's mainloop (host) which starts the backend as a guest, then finally the Kernel is started.

  2. The asyncio implementation of start_guest_run was written by the author of aiologic and provided as a gist. 2

  3. trio's start_guest_run. 2

  4. 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.

  5. free threading terminology

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.19.0.tar.gz (321.4 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.19.0-py3-none-any.whl (118.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for async_kernel-0.19.0.tar.gz
Algorithm Hash digest
SHA256 1d3544f823cdb0ba762d21fea33e5902f86feef3cbc4568457b13b9c5a752448
MD5 725b7cc920ba0d5352762bc31d66e84c
BLAKE2b-256 6857832e3e387a31aee1ab15fbe4bc0ef023f73e39fba0b98589d031ddd8e75a

See more details on using hashes here.

Provenance

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

File metadata

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

File hashes

Hashes for async_kernel-0.19.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ca5cd2d05032f3a27fce4b6c8e88b96e5f3ba6e162872b361ebe81806c127b2a
MD5 6a4d55f61cd3afba401de05e4a4660ce
BLAKE2b-256 1fd7135d2da7368c4b753f6fc055d36d989c8e3a4306076281751d0f0d078b61

See more details on using hashes here.

Provenance

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