【发布时间】:2017-03-20 21:56:28
【问题描述】:
我想并行运行四个 .exe。在第一个 .exe 的第一次迭代之后,第二个 .exe 必须启动,而第一个继续其第二次迭代,以此类推。目标是四个并行的数据相互反馈。 exe是用Fortran 90编写的,但代码是在linux python中的。
import os, threading
e = range(10)
for a in e:
def exe1():
os.system("./exe1")
t1 = threading.Thread(target=exe1, args=())
t1.start()
t1.join()
if a > 0:
for b in e:
def exe2():
os.system("./exe2")
t2 = threading.Thread(target=exe2, args=())
t2.start()
t2.join()
if b > 0:
for c in e
def exe3():
os.system("./exe3")
t3 = threading.Thread(target=exe3, args=())
t3.start()
t3.join()
if c > 0:
for d in e
def exe4():
os.system("./exe4")
t4 = threading.Thread(target=exe4, args=())
t4.start()
t4.join()
这是我的想法,但我没有能力并行运行它们。他们每个人必须进行 10 次迭代。
【问题讨论】:
-
如果你
join只要你start你的线程,难怪它为什么不并行运行。 -
那里只有一个函数定义的循环是什么?病了!
-
看看subprocess 模块。它可能更适合您正在做的事情。
-
我不认为并行意味着你认为的意思,我的朋友。
-
你的缩进真的不对。差点让我错过了重点。
标签: python linux parallel-processing