结果是一个非常大的变量,我会这样做:
results = sum(results, [])
print 'Writing results json to %s' % res_file
with open(res_file, 'w') as f:
json.dump(results, f, sort_keys=True, indent=4)
为它。但是如何在生成过程中存储大变量?
pool = mp.Pool(8)
results = pool.map(coco_results_one_category_kernel, data_pack)
pool.close()
pool.join()
此代码无法为多处理分配内存:
OSError:[Errno 12]无法分配内存
results = []
for i in range(len(data_pack)):
print i,'/',len(data_pack)
results.append(coco_results_one_category_kernel(data_pack[i]))
results = sum(results, [])
由于结果太大,此代码将在i=36
时被终止。我怎么能这样做?我不在乎时间,只是得到结果变量。