我知道 Stack Exchange 上有很多关于将结果从多处理写入单个文件的帖子,并且我只阅读了这些帖子就开发了我的代码。我想要实现的是并行运行“RevMapCoord”函数,并使用 multiprocess.queue 将其结果写入一个文件中。但是我在排队工作时遇到了问题。我的代码:
def RevMapCoord(list):
"Read a file, Find String and Do something"
def feed(queue, parlist):
for par in parlist:
print ('Echo from Feeder: %s' % (par))
queue.put(par)
print ('**Feeder finished queing**')
def calc(queueIn, queueOut):
print ('Worker function started')
while True:
try:
par = queueIn.get(block = False)
res = RevMapCoord(final_res)
queueOut.put((par,res))
except:
break
def write(queue, fname):
fhandle = open(fname, "w")
while True:
try:
par, res = queue.get(block = False)
print >>fhandle, par, res
except:
break
fhandle.close()
feedProc = Process(target = feed , args = (workerQueue, final_res))
calcProc = [Process(target = calc , args = (workerQueue, writerQueue)) for i in range(nproc)]
writProc = Process(target = write, args = (writerQueue, sco_inp_extend_geno))
feedProc.start()
print ('Feeder is joining')
feedProc.join ()
for p in calcProc:
p.start()
for p in calcProc:
p.join()
writProc.start()
writProc.join ()
当我运行此代码时,脚本停留在“feedProc.start()”步骤。屏幕的最后几行输出显示了“feedProc.start()”末尾的打印语句:
Echo from Feeder: >AK779,AT61680,50948-50968,50959,6,0.406808,Ashley,Dayne
Echo from Feeder: >AK832,AT30210,1091-1111,1102,7,0.178616,John,Caine
**Feeder finished queing**
但在执行下一行“feedProc.join()”之前挂起。代码没有错误并继续运行但什么都不做(挂起)。请告诉我我犯了什么错误。