Skip to main content

conkernelclient

Background

Jupyter’s KernelClient is designed around a simple request-reply pattern: you send one message on the shell channel, wait for its reply, then send the next. This works fine for a single-threaded notebook, but falls apart when you need concurrent execution. For instance, running multiple cells in parallel, or letting an LLM tool loop fire off code while a long-running computation is still in flight. The underlying ZMQ socket isn’t safe to share across tasks, and there’s no built-in mechanism to route replies back to the correct caller when multiple requests are outstanding.

conkernelclient solves this with ConKernelClient, a drop-in replacement for AsyncKernelClient that makes concurrent execute() calls safe. It patches Session.send to synchronise with the ZMQ I/O thread (preventing a race where two sends interleave), and spins up a dedicated reader task on the shell channel that demultiplexes incoming replies by message ID. Each execute(..., reply=True) call gets its own asyncio.Queue, so multiple coroutines can await their replies independently without interfering with each other.

Installation

Install from pypi

$ pip install conkernelclient

How to use

from conkernelclient import *

The main entry point is ConKernelManager, a drop-in replacement for AsyncKernelManager that creates ConKernelClient instances. Start a kernel and connect a client in the usual way:

import asyncio
from jupyter_client.session import Session
km = ConKernelManager(session=Session(key=b'x'))
await km.start_kernel()
kc = await km.client().start_channels()
await kc.is_alive()
True

Once connected, execute() works like the standard client. Pass reply=True to await the shell reply, or reply=False (the default) to fire-and-forget and collect results later via get_pubs:

r = await kc.execute('2+1', timeout=1, reply=True)
r['content']['status']
'ok'

The key feature is safe concurrent execution. Multiple execute(..., reply=True) calls can be outstanding simultaneously — each gets its own asyncio.Queue, and a background reader task routes replies by message ID:

from fastcore.test import test_eq
a = kc.execute('x=2', reply=True)
b = kc.execute('y=3', reply=True)
r = await asyncio.wait_for(asyncio.gather(a, b), timeout=2)
test_eq(len(r), 2)
r[0]['parent_header']['msg_id']
'8c84fe1c-20242a1940eecfc5a1a31500_61486_3'

Both replies arrive independently, each routed to the correct caller. Without ConKernelClient, the second execute would either block waiting for the first to finish, or the replies would get crossed.

As usual, we clean up when we’re done:

if await km.is_alive():
    kc.stop_channels()
    await km.shutdown_kernel()

Download files

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

Source Distribution

conkernelclient-0.0.20.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

conkernelclient-0.0.20-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file conkernelclient-0.0.20.tar.gz.

File metadata

  • Download URL: conkernelclient-0.0.20.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.15

File hashes

Hashes for conkernelclient-0.0.20.tar.gz
Algorithm Hash digest
SHA256 30426c1a48f59a9ec8aba87df80c992cf74ba7385f4c46a76b12be2462d66528
MD5 647fe5445ccbaf12c15f439f3adfb3c7
BLAKE2b-256 4b2a1c23a159c599d3fafa5d0962c1d3088e64baf43289e990003442212eefe9

See more details on using hashes here.

File details

Details for the file conkernelclient-0.0.20-py3-none-any.whl.

File metadata

File hashes

Hashes for conkernelclient-0.0.20-py3-none-any.whl
Algorithm Hash digest
SHA256 50b41c5a2a751219eca4de3bfef74a4563265a0fff127527b6ff670949aae376
MD5 50d55752365819ee72ec6d1fbef1e979
BLAKE2b-256 dda6ca45458011e8aed4fb69bc43bca079168229d98b7b1feba8c28fac1286c9

See more details on using hashes here.

Release history Release notifications | RSS feed

0.0.22

2 files

0.0.21

2 files

This release

0.0.20 This release

2 files

0.0.19

2 files

0.0.18

2 files

0.0.17

2 files

0.0.16

2 files

0.0.15

2 files

0.0.14

2 files

0.0.13

2 files

0.0.12

2 files

0.0.11

2 files

0.0.10

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page