运行 shell 使用 dask 分布式并行命令
Running shell commands in parallel using dask distributed
我有一个包含很多 .sh 脚本的文件夹。我如何使用已经设置好的 dask 分布式集群来并行 运行 它们?
目前,我正在做以下事情:
import dask, distributed, os
# list with shell commands that I want to run
commands = ['./script1.sh', './script2.sh', './script3.sh']
# delayed function used to execute a command on a worker
run_func = dask.delayed(os.system)
# connect to cluster
c = distributed.Client('my_server:8786')
# submit job
futures = c.compute( [run_func(c) for c in commands])
# keep connection alive, do not exit python
import time
while True:
time.sleep(1)
这可行,但是对于这种情况,如果客户端可以断开连接而不导致调度程序取消作业,那将是理想的。我正在寻找一种不需要活动客户端连接来计算我的任务的方法。这怎么可能?
你见过http://distributed.readthedocs.io/en/latest/api.html#distributed.client.fire_and_forget吗?这将是一种确保在客户端离开后某些任务在集群上运行的方法。
另请注意,您拥有 wait()
甚至 gather()
等函数,因此您不需要 sleep-forever 循环。
不过,一般来说,subprocess.Popen
会启动一个子进程,不会 等待它完成,所以你甚至不需要任何复杂的东西,因为您似乎对通话的任何输出都不感兴趣。
我有一个包含很多 .sh 脚本的文件夹。我如何使用已经设置好的 dask 分布式集群来并行 运行 它们?
目前,我正在做以下事情:
import dask, distributed, os
# list with shell commands that I want to run
commands = ['./script1.sh', './script2.sh', './script3.sh']
# delayed function used to execute a command on a worker
run_func = dask.delayed(os.system)
# connect to cluster
c = distributed.Client('my_server:8786')
# submit job
futures = c.compute( [run_func(c) for c in commands])
# keep connection alive, do not exit python
import time
while True:
time.sleep(1)
这可行,但是对于这种情况,如果客户端可以断开连接而不导致调度程序取消作业,那将是理想的。我正在寻找一种不需要活动客户端连接来计算我的任务的方法。这怎么可能?
你见过http://distributed.readthedocs.io/en/latest/api.html#distributed.client.fire_and_forget吗?这将是一种确保在客户端离开后某些任务在集群上运行的方法。
另请注意,您拥有 wait()
甚至 gather()
等函数,因此您不需要 sleep-forever 循环。
不过,一般来说,subprocess.Popen
会启动一个子进程,不会 等待它完成,所以你甚至不需要任何复杂的东西,因为您似乎对通话的任何输出都不感兴趣。