首页 > 解决方案 > 通过 dask 在 python 脚本中进行任务管理和监控

问题描述

我有一个包含许多子文件夹的项目文件夹(比如 100 个)。python 脚本导航到每个子文件夹,调用可执行文件,将结果写入输出文件并移动到下一个子文件夹。

这是我的python脚本

from dask_jobqueue import PBSCluster   
cluster = PBSCluster()
cluster.scale(jobs=3)  

from dask.distributed import Client
client = Client(cluster)
...

r_path='/path/to/project/folder'


def func():
    f = open('out', 'w')
   (subprocess.call(["/path/to/executable/file"], stdout=f))

for root, dirs, files in os.walk("."):
    for name in dirs:
        os.chdir(r_path+'/'+str(name))
        func()

在项目中,

  1. 输出文件需要用于进一步计算,因此脚本需要知道给定子文件夹的执行何时完成
  2. 可执行文件需要在任何给定时间限制为 10 个子文件夹,并且在这 10 个子文件夹中,在任何执行完成后,需要启动另一个子文件夹中的新文件夹。

有人可以让我知道是否可以使用 dask 来做到这一点?

标签: pythondaskdask-delayed

解决方案


是的,可以使用 Dask 来执行此操作。您可能想阅读有关 Dask 延迟或 Dask 期货的文档。

https://docs.dask.org/en/latest/delayed.html

https://docs.dask.org/en/latest/futures.html


推荐阅读