First page Back Continue Last page Overview Graphics

Pool

The Pool object offers a convenient means of parallelizing the execution of a function across multiple input values, distributing the input data across processes (data parallelism).

from multiprocessing import Pool

C = [3.4, 8.9, 5.9, 10.3]

def fahrenheit(t):

return 9*t/5 + 32

with Pool(5) as p:

print(p.map(fahrenheit, C))

Output:

[38.12, 48.02, 42.620000000000005, 50.54]