我有一個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