与 GNU Make 等 Python 相关的并行任务并发

Bri*_*man 5 python parallel-processing concurrency dependencies makefile

我正在寻找一种方法或者可能是一种哲学方法来如何在 python 中执行类似 GNU Make 的操作。目前,我们使用 makefile 来执行处理,因为 makefile 非常擅长通过更改单个选项:-j x 进行并行运行。此外,gnu make 已经内置了依赖堆栈,因此添加辅助处理器或处理更多线程的能力仅意味着更新该单个选项。我希望 python 具有同样的功能和灵活性,但我没有看到。

举个例子:

all:  dependency_a dependency_b dependency_c

dependency_a:  dependency_d
    stuff

dependency_b:  dependency_d
    stuff

dependency_c:  dependency_e
    stuff

dependency_d:  dependency_f
    stuff

dependency_e:
    stuff

dependency_f:
    stuff
Run Code Online (Sandbox Code Playgroud)

如果我们执行标准单线程操作(-j 1),操作顺序可能是:

dependency_f -> dependency_d -> dependency_a -> dependency_b -> dependency_e \
             -> dependency_c
Run Code Online (Sandbox Code Playgroud)

对于两个线程 (-j 2),我们可能会看到:

1: dependency_f -> dependency_d -> dependency_a -> dependency_b

2: dependency_e -> dependency_c
Run Code Online (Sandbox Code Playgroud)

有人对已经构建的包或方法有什么建议吗?我完全开放,只要它是一个Python式的解决方案/方法。

请提前致谢!

Nic*_*tin 0

您应该使用Scons,因为它已经完成了您想要的计算,并且您可以颠覆它以执行几乎任何操作(例如 Make)。