gpt4 book ai didi

ipython - 从代码启动ipcluster

转载 作者:行者123 更新时间:2023-12-02 04:32:19 26 4
gpt4 key购买 nike

我想从我的 Jupyter notebook 动态启动集群以实现特定功能。虽然我可以启动集群并使引擎运行,但我有两个问题:

(1) 我无法在后台运行ipcluster 命令。当我通过笔记本运行命令时,单元一直运行到集群运行的时间,即我无法在同一个笔记本中运行更多单元。一旦引擎在不同的笔记本中启动,我就可以使用它们。如何在后台运行ipcluster?

(2) 我的代码总是启动8个引擎,不管ipcluster_config.py中的设置如何。

代码:

server_num = 3
ip_new = '10.0.1.' + str(10+server_num)
cluster_profile = "ssh" + str(server_num)

import commands
import time
commands.getstatusoutput("ipython profile create --parallel --profile=" + cluster_profile)

text = """
c.SSHEngineSetLauncher.engines = {'""" +ip_new + """' : 12}
c.LocalControllerLauncher.controller_args = ["--ip=10.0.1.163"]
c.SSHEngineSetLauncher.engine_cmd = ['/home/ubuntu/anaconda2/pkgs/ipyparallel-6.0.2-py27_0/bin/ipengine']
"""

with open("/home/ubuntu/.ipython/profile_" + cluster_profile + "/ipcluster_config.py", "a") as myfile:
myfile.write(text)

result = commands.getstatusoutput("(ipcluster start --profile='"+ cluster_profile+"' &)")
time.sleep(120)
print(result[1])

最佳答案

当我在 StackOverflow 上看到您的答案没有得到答复时,我差点心脏病发作,因为我遇到了同样的问题。

但是运行

ipcluster start --help 

命令显示了这一点:
--daemonize

这使它在后台运行。

所以在你的笔记本中你可以这样做:
no_engines = 6
!ipcluster start -n {no_engines} --daemonize

注:这在 Windows 上不起作用,根据
ipcluster start --help

关于ipython - 从代码启动ipcluster,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47540186/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com