9

I want to mimic the functionality of a notebook server, and instead coordinate the creation/management of different IPython/Jupyter kernels from a central body of logic (i.e. my own Python script).

For example, I want to:

  • Define an abstract command e.g. "add(x, y)"
  • Communicate the abstract command to multiple kernels e.g. an IPython kernel and Scala kernel
  • Have each kernel execute the command however they wish
  • Return the result from each kernel to the central body of logic

Can anyone point me in the direction of how to programmatically start/stop/communicate with multiple IPython/Jupyter kernels?

trianta2
  • 3,952
  • 5
  • 36
  • 52

1 Answers1

7

A KernelManager deals with starting and stopping a single kernel, and there's a MultiKernelManager to co-ordinate more than one.

Then you can use the .client() method to get a KernelClient instance which handles communications with a kernel:

For details of how you communicate with a kernel, see the message spec docs. Some of this is abstracted away by KernelClient, but you'll probably need to know some of it.

Thomas K
  • 39,200
  • 7
  • 84
  • 86
  • Can you update this answer for the newer versions? Also, can one interact with "native kernels" like IJulia via Python, too? – HappyFace Sep 29 '21 at 11:58
  • 1
    The relevant APIs moved to the [jupyter_client package](https://jupyter-client.readthedocs.io/en/stable/api/index.html), but otherwise are still fairly similar. They work for Jupyter kernels in any language. – Thomas K Sep 29 '21 at 16:57