我想同时调查四个前男友。在第一个.exe的第一次迭代之后,第二个.exe必须启动,而第一个继续第二次迭代,依此类推。目标是四个并行的数据反馈。exe是用fortran90编写的,但是代码是用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次迭代。你知道吗
我不会对定义函数的循环做进一步的评论(非常奇怪),可能是因为缩进已经关闭了,所以可能会有更多的4个线程并行(我已经了解了很多)。你知道吗
但是要回答您的问题,您的x可执行文件并不是并行运行的,因为您在线程上使用
join()
,只要您一启动它。你知道吗所以主程序在尝试启动另一个线程之前,会等待当前线程终止。你知道吗
我会这样做:
在你的节目开始的时候。你知道吗
每次创建线程时,将其引用存储在
thread_list
:然后,删除程序中的所有
join
调用。现在您实际上是在x线程中并行地启动x进程。你知道吗在程序结束时,等待所有线程完成:
相关问题 更多 >
编程相关推荐