[[0], [0, 1]]如果使用map_async,则使用结果()调用一次回调。
>>> from multiprocessing import Pool>>> def myfunc(x):... return [i for i in range(x)]... >>> A = []>>> def mycallback(x):... print('mycallback is called with {}'.format(x))... A.extend(x)... >>> pool=Pool()>>> r = pool.map_async(myfunc, (1,2), callback=mycallback)>>> r.wait()mycallback is called with [[0], [0, 1]]>>> print(A)[[0], [0, 1]]
使用
apply_async,如果你想被称为每次回调。
pool=Pool()results = []for x in (1,2): r = pool.apply_async(myfunc, (x,), callback=mycallback) results.append(r)for r in results: r.wait()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)