2016-12-22 54 views
3

我只是想知道是否有一些python代码或我可以执行的魔法将重新启动ipython集群。似乎每次我更改我的代码时,都需要重新启动它。我可以从笔记本重新启动iPython群集吗?

+0

我不知道是否有一个笔记本扩展可以做到这一点,但我会怀疑在笔记本内部运行的代码重新启动它,可能会导致无限循环的运行重新启动。 –

回答

0

一个简单的想法,似乎是太生产的“哈克”:

设置的Client并定义用于测试的简单功能。

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] 

定义重新启动集群的功能。 shutdowntargets='all'hub=True应该杀死整个群集。然后用!%sx魔法命令启动一个新簇。

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.remotedv.parallel或需要的任何功能。

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

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

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

读取源为ipyparallel Client,上述shutdown方法具有关键字参数,restart=False,但它目前未实现。也许开发者正在开发一种可靠的方法。

+0

感谢您的建议;我会放弃它。主设计笔记本电脑没有过程控制的原因是否有原因? – cjm2671