我从简单的例子中了解到,Pool.map应该与' normal'相同。下面的python代码除了并行:
def f(x):
# complicated processing
return x+1
y_serial = []
x = range(100)
for i in x: y_serial += [f(x)]
y_parallel = pool.map(f, x)
# y_serial == y_parallel!
但是我有两位代码,我认为应该遵循这个例子:
#Linear version
price_datas = []
for csv_file in loop_through_zips(data_directory):
price_datas += [process_bf_data_csv(csv_file)]
#Parallel version
p = Pool()
price_data_parallel = p.map(process_bf_data_csv, loop_through_zips(data_directory))
然而,并行代码不起作用,而线性代码则不起作用。从我可以观察到,并行版本似乎循环通过生成器(它从生成器函数打印出日志行)但实际上没有执行" process_bf_data_csv"功能。我在这里做错了什么?
答案 0 :(得分:2)