multiprocessing.Pool
この状況での Python の動作がわかりません。
import multiprocessing
def f(x): return x
P = multiprocessing.Pool()
def f(x): return x*x
print (P.map(f, range(10)))
print ( map(f, range(10)))
出力は次のようになります。
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
print ステートメントが呼び出される時点で、単一のf
. Pool が の最初のインスタンスを取得するのはなぜf
ですか? 私はそれを期待しP.map
、map
同じ結果を出力するでしょう!