我想利用多处理来并行创建单个csv文件,但到目前为止,结果还是很糟糕。我创建了一个嵌套列表,在没有多处理的情况下执行序列化时,该列表的维度应为50乘10。但是,生成的csv文件包含每个列表作为元素。我该怎么解决这个问题?
from multiprocessing import Pool
def sample(key):
sample_list = [[34 for i in range(10)] for i in range(50)]
return sample_list
pool = Pool(processes=2) # Number of cores I'm using
resultset = pool.imap(sample, list(range(25)), chunksize=25)
with open('./testing.csv','w') as f:
writer = csv.writer(f, delimiter=',')
for result in resultset:
for row in result:
writer.writerow(row)