我可以从笔记本电脑重新启动iPython群集吗?

我可以从笔记本电脑重新启动iPython群集吗?,python,jupyter,ipython-parallel,Python,Jupyter,Ipython Parallel,我只是想知道我是否可以执行一些python代码或魔法来重新启动ipython集群。似乎每次我更改代码时,都需要重新启动。一个简单的想法,对于生产来说似乎太“黑客”了: 设置客户端并定义一个简单的测试功能 import ipyparallel as ipp c = ipp.Client() dv = c[:] # simple function @dv.remote(block=True) def getpid(): import os return os.getpid() g

我只是想知道我是否可以执行一些python代码或魔法来重新启动ipython集群。似乎每次我更改代码时,都需要重新启动。

一个简单的想法,对于生产来说似乎太“黑客”了:

设置
客户端
并定义一个简单的测试功能

import ipyparallel as ipp
c = ipp.Client()
dv = c[:]

# simple function
@dv.remote(block=True)
def getpid():
    import os
    return os.getpid()

getpid()
[1994, 1995, 1998, 2001]
定义一个函数来重新启动集群。使用
targets='all'
hub=True
应该杀死整个集群。然后用
启动一个新集群或魔术命令

import time
def restart_ipcluster(client):
    client.shutdown(targets='all', hub=True)
    time.sleep(5) # give the cluster a few seconds to shutdown

    # include other args as necessary
    !ipcluster start -n4 --daemonize
    time.sleep(60) # give cluster ~min to start

    return ipp.Client() # with keyword args as necessary
这种方法的一个缺点是需要重新分配DirectView,并且需要重新执行用
dv.remote
dv.parallel
修饰的任何函数

c = restart_ipcluster(c)    
dv = c[:]

@dv.remote(block=True)
def getpid():
    import os
    return os.getpid()

getpid()
[3620, 3621, 3624, 3627]

读取ipyparallel
客户机的源代码时,上面提到的
shutdown
方法有一个关键字参数,
restart=False
,但目前尚未实现。也许开发人员正在研究一种可靠的方法

我想知道是否有一个笔记本扩展可以做到这一点,但我怀疑笔记本中运行的重新启动它的代码是否会导致无限循环的运行-重新启动;我要试一试。从设计上看,主笔记本没有过程控制,这有什么原因吗?