这个问题与previous question I asked有关,看起来很简单,但我很难找到有关多处理主题的有用信息或教程。
我的问题是,我想把产生的数据组合成一个大数组,然后将其存储在我的hdf文件中。
def Simulation(i, output):
# make a simulation which outputs it resutlts in A. with shape 4000,3
A = np.array([4000,3])
output.put(A)
def handle_output(output):
hdf = pt.openFile('simulation.h5',mode='w')
hdf.createGroup('/','data')
# Here the output should be joined somehow.
# I would like to get it in the shape [4000,3,10]
output.get()
hdf.createArray('/data','array',A)
hdf.close()
if __name__ == '__main__':
output = mp.Queue()
jobs = []
proc = mp.Process(target=handle_output, args=(output, ))
proc.start()
for i in range(10):
p = mp.Process(target=Simulation, args=(i, output))
jobs.append(p)
p.start()
for p in jobs:
p.join()
output.put(None)
proc.join()
你真正需要的是一个多处理池
做点什么,比如:
相关问题 更多 >
编程相关推荐