我有以下功能
from multiprocessing import Pool
def do_comparison(tupl):
x, y = tupl # unpack arguments
return compare_clusters(x, y)
def distance_matrix(clusters, condensed=False):
pool = Pool()
values = pool.map_async(do_comparison, itertools.combinations(clusters, 2)).get()
do stuff
是否可以打印进度pool.map_async(do_comparison, itertools.combinations(clusters, 2)).get()
?我通过像这样向 do_comparison 添加计数来尝试它
count = 0
def do_comparison(tupl):
global count
count += 1
if count % 1000 == 0:
print count
x, y = tupl # unpack arguments
return compare_clusters(x, y)
但除了看起来不是一个好的解决方案之外,这些数字直到脚本结束才会打印出来。有没有好的方法来做到这一点?