以下使用多处理程序包的代码无限运行,并且产生的错误消息显示“未创建子进程”:
if __name__ == '__main__':
data = xlrd.open_workbook("workbook.xlsx")
data_all=[]
for sheetname in data.sheet_names() :
#read all rows in all sheets into list of lists
sh = data.sheet_by_name(sheetname)
for rownum in range(sh.nrows) :
data_all.append(sh.row_values(rownum))
data_chunks=np.array_split(data_all,5)
output=mp.Queue()
processes=[mp.Process(target=main,args=(chunk_l,)) for chunk_l in data_chunks]
#runtime
start_time = time.time()
#Run processes
for p in processes:
p.start()
#Exit completed processes
for p in processes:
p.join()
#Get results from output queue
results=[output.get() for p in processes]
#runtime
end_time=time.time()
一段时间后,我停止了该过程,好像卡在了p.join()上:
---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
<ipython-input-11-83ace3c1f041> in <module>()
20 #Exit completed processes
21 for p in processes:
---> 22 p.join()
23
24 #Get results from output queue
~/anaconda3/lib/python3.6/multiprocessing/process.py in join(self, timeout)
122 assert self._parent_pid == os.getpid(), 'can only join a child process'
123 assert self._popen is not None, 'can only join a started process'
--> 124 res = self._popen.wait(timeout)
125 if res is not None:
126 _children.discard(self)
~/anaconda3/lib/python3.6/multiprocessing/popen_fork.py in wait(self, timeout)
49 return None
50 # This shouldn't block if wait() returned successfully.
---> 51 return self.poll(os.WNOHANG if timeout == 0.0 else 0)
52 return self.returncode
53
~/anaconda3/lib/python3.6/multiprocessing/popen_fork.py in poll(self, flag)
27 while True:
28 try:
---> 29 pid, sts = os.waitpid(self.pid, flag)
30 except OSError as e:
31 # Child process not yet created. See #1731717
我用于处理的main()函数以output.put结尾,以存储给定数据块产生的结果。我很确定这会一直根据正在运行的output.put()之后的打印语句运行,根据我的理解,这意味着将创建并运行子进程。有谁对如何调试有任何想法?