A concurrent python kernel for Jupyter supporting AnyIO, AsyncIO and Trio.
Project description
async kernel
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:
- Direct ZMQ socket messaging via a configuration file and kernel spec - (Jupyter, VScode, etc).
- An experimental callback style interface (Jupyterlite).
Highlights
- IPython shell
- anyio compatible asynchronous backend (
asyncio(default) ortrio) - aiologic thread-safe synchronisation primitives
- Backend agnostic multi-thread / multi-event loop management
- Per-subshell user_ns
- GUI event loops [^1][^2]
- inline
- ipympl
- tk host and asyncio[^3] or trio[^4] backend running as a guest
- qt host and asyncio[^3] or trio[^4] backend running as a guest
- Experimental support for Jupyterlite (try it online here 👈)
- Debugger client
[^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 per 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 the blocking 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.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file async_kernel-0.13.0.tar.gz.
File metadata
- Download URL: async_kernel-0.13.0.tar.gz
- Upload date:
- Size: 305.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
415e4a0ff04354feb5b3d111e9f5bfb1432085ad37fe9aa805bef999165e4d86
|
|
| MD5 |
905440abaa6aad44e63f2a126524ccaf
|
|
| BLAKE2b-256 |
6809a71cb42e3d6e6e1a5452c9235073f39b2d2f5c8db6c978f125d9e7a4b8b1
|
Provenance
The following attestation bundles were made for async_kernel-0.13.0.tar.gz:
Publisher:
publish-to-pypi.yml on fleming79/async-kernel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
async_kernel-0.13.0.tar.gz -
Subject digest:
415e4a0ff04354feb5b3d111e9f5bfb1432085ad37fe9aa805bef999165e4d86 - Sigstore transparency entry: 1006177644
- Sigstore integration time:
-
Permalink:
fleming79/async-kernel@53ba847ff4435ebddfddde545f7e3a13746e9ad6 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/fleming79
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@53ba847ff4435ebddfddde545f7e3a13746e9ad6 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file async_kernel-0.13.0-py3-none-any.whl.
File metadata
- Download URL: async_kernel-0.13.0-py3-none-any.whl
- Upload date:
- Size: 108.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b56ff780012ea512123311ef4db751460df749347dbacc1427d4f8f4b2f80d67
|
|
| MD5 |
a8cb63d547c9a73258d4dab049e7a4f0
|
|
| BLAKE2b-256 |
db20c78f7c7a1a2feec531d9ae7dd3b2e905b1caa972c9aa42c9eae7dca165a1
|
Provenance
The following attestation bundles were made for async_kernel-0.13.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on fleming79/async-kernel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
async_kernel-0.13.0-py3-none-any.whl -
Subject digest:
b56ff780012ea512123311ef4db751460df749347dbacc1427d4f8f4b2f80d67 - Sigstore transparency entry: 1006177645
- Sigstore integration time:
-
Permalink:
fleming79/async-kernel@53ba847ff4435ebddfddde545f7e3a13746e9ad6 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/fleming79
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@53ba847ff4435ebddfddde545f7e3a13746e9ad6 -
Trigger Event:
workflow_run
-
Statement type: