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

查看:186
本文介绍了如何从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).

例如,我想:


  • 定义抽象命令,例如add(x,y)

  • 将抽象命令传递给多个内核,例如:一个IPython内核和Scala内核

  • 让每个内核按照自己的意愿执行命令

  • 将结果从每个内核返回到逻辑的中心体

  • 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

有人能指出我如何以编程方式启动/停止/与多个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.

  • http://ipython.org/ipython-doc/3/api/generated/IPython.kernel.manager.html
  • http://ipython.org/ipython-doc/3/api/generated/IPython.kernel.multikernelmanager.html

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

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

  • http://ipython.org/ipython-doc/3/api/generated/IPython.kernel.client.html

有关如何与内核通信的详细信息,请参阅消息规范文档。其中一些是由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天全站免登陆