我有一个python脚本来使用os.subprocess模块运行一些外部命令。但其中一个步骤需要很长时间,所以我想单独运行。我需要启动它们,检查它们是否完成,然后执行下一个不平行的命令。 我的代码是这样的:如何在python中运行并行程序
nproc = 24
for i in xrange(nproc):
#Run program in parallel
#Combine files generated by the parallel step
for i in xrange(nproc):
handle = open('Niben_%s_structures' % (zfile_name), 'w')
for i in xrange(nproc):
for zline in open('Niben_%s_file%d_structures' % (zfile_name,i)):handle.write(zline)
handle.close()
#Run next step
cmd = 'bowtie-build -f Niben_%s_precursors.fa bowtie-index/Niben_%s_precursors' % (zfile_name,zfile_name)
这实际上并没有做任何事情,因为'join()'阻塞(阻止其他线程开始),直到线程完成。看到我的答案如何解决这个问题。 – pR0Ps 2012-08-14 14:32:15