如何从 Python 脚本管理多个 IPython/Jupyter 内核并与之通信? [英] How to manage and communicate with multiple IPython/Jupyter kernels from a Python script?

查看:48
本文介绍了如何从 Python 脚本管理多个 IPython/Jupyter 内核并与之通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想模仿笔记本服务器的功能,而是从一个中央逻辑主体(即我自己的 Python 脚本)协调不同 IPython/Jupyter 内核的创建/管理.

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).

例如,我想:

  • 定义一个抽象命令,例如添加(x,y)"
  • 将抽象命令传达给多个内核,例如一个 IPython 内核和 Scala 内核
  • 让每个内核按照自己的意愿执行命令
  • 将每个内核的结果返回给逻辑的中央主体

谁能给我指出如何以编程方式启动/停止/与多个 IPython/Jupyter 内核通信的方向?

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

推荐答案

一个 KernelManager 处理启动和停止单个内核,还有一个 MultiKernelManager 来协调多个内核.

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

然后您可以使用 .client() 方法来获取处理与内核通信的 KernelClient 实例:

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

有关如何与内核通信的详细信息,请参阅消息规范文档.其中一些已被 KernelClient 抽象出来,但您可能需要了解其中的一些.

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.

这篇关于如何从 Python 脚本管理多个 IPython/Jupyter 内核并与之通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆