0
私は、同じタスクを達成するために、これらの2つのアプローチがあるとしますが...私はfuncは実行が終了していない場合しかし、x.get()はまだメインスレッドをブロックする可能性があります、すぐにapply_asyncリターンを実現Pythonマルチプロセッシングのstarmapとapply_asyncの比較は速いですか?
from multiprocessing import Pool
pool = Pool(4)
def func(*args):
# do some slow operations
return something
dates = ['2011-01-01', ' 2011-01-02', ... , '2017-01-01']
other_args = [1, 2, 3, 'c', 'test', 'pdf')]
# approach 1:
res = [pool.apply_async(func, [day] + other_args) for day in dates]
list_of_results = [x.get() for x in res]
# approach 2: create an iterable of iterables
args = [[day] + other_args for day in dates]
list_of_results = pool.starmap(func, args)
をこれらの2つの方法の間には必ず性能差がありますか?
非同期メソッドを使用する上でのポイントは、後で使用されるため、結果を待つことを避けることです。 –