jellycell.run.pool

Kernel reuse across multiple :class:Runner.run calls.

Each jellycell run spawns a fresh Jupyter kernel subprocess (~2s setup, ~1s shutdown). Over render_all on a project with N notebooks that’s N kernel churns for no reason — the kernel protocol has a %reset -f magic for exactly this case.

Usage::

pool = KernelPool(kernel_name="python3")
runner = Runner(project, kernel_pool=pool)
try:
    for nb in notebooks:
        runner.run(nb)
finally:
    pool.close()

The pool holds exactly one long-lived kernel (maxsize=1) for now — most projects are single-kernel. A multi-kernel pool is straightforward to add if someone needs parallel execution later.

Module Contents

Classes

KernelPool

Holds one long-lived kernel, resetting its namespace between runs.

API

class jellycell.run.pool.KernelPool(kernel_name: str = 'python3')

Holds one long-lived kernel, resetting its namespace between runs.

acquire() returns a kernel. If the pool’s kernel died between calls (subprocess crashed), a new one is spawned transparently.

Initialization

acquire() jellycell.run.kernel.Kernel

Return a ready-to-use kernel. Starts or resets as needed.

close() None

Stop the underlying kernel. Idempotent.