Skip to main content

An asynchronous Python Jupyter kernel

Project description

Build Status Code style: black

akernel

An asynchronous Python Jupyter kernel.

Motivation

ipykernel offers the ability to run asynchronous code from the REPL. This means you can await at the top-level, outside of a function. Unfortunately, this will still block the kernel.

akernel changes this behavior by launching each cell in a task.

Features

akernel allows for asynchronous code execution. What this means is that when used in a Jupyter notebook, you can run cells concurrently if the code is cooperative. For instance, you can run a cell with the following code:

# cell 1
for i in range(10):
    print("cell 1:", i)
    await asyncio.sleep(1)

Since this cell is async (it has an await), it will not block the execution of other cells. So you can run another cell concurrently, provided that this cell is also cooperative:

# cell 2
for j in range(10):
    print("cell 2:", j)
    await asyncio.sleep(1)

If cell 2 was blocking, cell 1 would pause until cell 2 was finished. You can see that by changing await asyncio.sleep(1) into time.sleep(1) in cell 2.

You can make a cell wait for the previous one to be finished with:

# cell 3
await __task__()  # wait for cell 2 to be finished
print("cell 2 has run")

Limitations

It is still a work in progress, in particular:

  • stdout/stderr redirection to the cell output is only supported through the print function.
  • No rich representation for now, only the standard __repr__ is supported. This means no matplotlib figure yet :-( But ipywidgets should work!
  • If the cell code has multiline strings, they must be wrapped with the textwrap.dedent function.

Project details


Download files

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

Source Distribution

akernel-0.0.9.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

akernel-0.0.9-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file akernel-0.0.9.tar.gz.

File metadata

  • Download URL: akernel-0.0.9.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for akernel-0.0.9.tar.gz
Algorithm Hash digest
SHA256 ab9cc311d2bf425284727f452a63a0bfe8b696e168ad168eb1d7f2d86819d7a9
MD5 4acab4d926d59a7e7cd73b01263d43bd
BLAKE2b-256 500bed8c3c6b421a654f6f9339039c07cf1ea65e8bfcd536f8bd112343c11e01

See more details on using hashes here.

File details

Details for the file akernel-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: akernel-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for akernel-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 cbc7de5ad1266b23e63366cb5f45afae2226555d2677859afa5b4bd25d71fdc1
MD5 4d52043d7f20a8782078661c24270b34
BLAKE2b-256 332504c9ece6f5bb7588f6171ee16f7e078c615f29eda3205ad17cb705b1a995

See more details on using hashes here.

Supported by

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