A concurrent python kernel for Jupyter supporting AnyIO, AsyncIO and Trio.
Project description
Async kernel
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
- Experimental support for Jupyterlite try it online here
- Concurrent message handling
- Configurable backend
- Debugger client
- anyio
asynciobackend (default)[^uv-loop]triobackend
- anyio
- IPython shell
- Thread-safe execution and cancellation (utilising aiologic synchronisation primitives).
- Jupyter Kernel Subshells
- GUI event loops
- inline
- ipympl
- tk
- qt
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 theMainThreadhandling 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.direct→Caller.call_direct: Run the request in the scheduler.RunMode.queue→Caller.queue_call: Run the request in a queue dedicated to the subshell, handler & channel.RunMode.task→Caller.call_soon: Run the request in a separate task.RunMode.thread→Caller.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
MsgTypedocs.Kernel.receive_msg_loopdocs.- Concurrency notebook.
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
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.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0eeae3fb281b0d360bfcb975d60daaa66fd4287e8f5805413db49790ae5acbad
|
|
| MD5 |
e64ba1f6f123426fe64f8a3717d059a3
|
|
| BLAKE2b-256 |
4c61c3c20d899bbc59f497b663e00149b95fd0be6955de75af5a935d0642df1f
|
Provenance
The following attestation bundles were made for async_kernel-0.11.2.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.11.2.tar.gz -
Subject digest:
0eeae3fb281b0d360bfcb975d60daaa66fd4287e8f5805413db49790ae5acbad - Sigstore transparency entry: 833829174
- Sigstore integration time:
-
Permalink:
fleming79/async-kernel@45355a78cfcb052133bec1f3674987fc3960230e -
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@45355a78cfcb052133bec1f3674987fc3960230e -
Trigger Event:
workflow_run
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b38021df0ca8f52ce51a10a7090613c57c9c2e4991e80a5ac8b0f90d4bbf4a13
|
|
| MD5 |
245d0a3e5008e62d3d5d0200eb3ce48f
|
|
| BLAKE2b-256 |
dbc8e7452eae1171a09d32be73241a8b46f2dbc062dd5d51ab4182a0efd82402
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
async_kernel-0.11.2-py3-none-any.whl -
Subject digest:
b38021df0ca8f52ce51a10a7090613c57c9c2e4991e80a5ac8b0f90d4bbf4a13 - Sigstore transparency entry: 833829175
- Sigstore integration time:
-
Permalink:
fleming79/async-kernel@45355a78cfcb052133bec1f3674987fc3960230e -
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@45355a78cfcb052133bec1f3674987fc3960230e -
Trigger Event:
workflow_run
-
Statement type: