Skip to content

Commit 2d7626c

Browse files
committed
add docs for pending kernels
1 parent 9bc967a commit 2d7626c

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ with Jupyter kernels.
2424
kernels
2525
wrapperkernels
2626
provisioning
27+
pending-kernels
2728

2829
.. toctree::
2930
:maxdepth: 2

docs/pending-kernels.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Pending Kernels
2+
===============
3+
4+
*Added in 7.1.0*
5+
6+
In scenarios where an kernel takes a long time to start (e.g. kernels running remotely), it can be advantageous to immediately return the kernel's model and ID from key methods like ``.start_kernel()`` and ``.shutdown_kernel()``. The kernel will continue its task without blocking other managerial actions.
7+
8+
This intermediate state is called a **"pending kernel"**.
9+
10+
How they work
11+
-------------
12+
13+
When ``.start_kernel()`` or ``.shutdown_kernel()`` is called, a ``Future`` is created under the ``KernelManager.ready`` property. This property can be awaited anytime to ensure that the kernel moves out of its pending state, e.g.:
14+
15+
.. code-block:: python
16+
17+
# await a Kernel Manager's `.ready` property to
18+
# block further action until the kernel is out
19+
# of its pending state.
20+
await kernel_manager.ready
21+
22+
Once the kernel is finished pending, ``.ready.done()`` will be ``True`` and either 1) ``.ready.result()`` will return ``None`` or 2) ``.ready.exception()`` will return a raised exception
23+
24+
Using pending kernels
25+
---------------------
26+
27+
The most common way to interact with pending kernels is through the ``MultiKernelManager``—the object that manages a collection of kernels—by setting its ``use_pending_kernels`` trait to ``True``. Pending kernels are "opt-in"; they are not used by default in the ``MultiKernelManager``.
28+
29+
When ``use_pending_kernels`` is ``True``, the following changes are made to the ``MultiKernelManager``:
30+
31+
1. ``start_kernel`` and ``stop_kernel`` return immediately while running the pending task in a background thread.
32+
2. The following methods raise a ``RuntimeError`` if a kernel is pending:
33+
* ``restart_kernel``
34+
* ``interrupt_kernel``
35+
* ``shutdown_kernel``
36+
3. ``shutdown_all`` will wait for all pending kernels to become ready before attempting to shut them down.

0 commit comments

Comments
 (0)