Message287895
The »basic example of data parallelism using Pool« is too basic. It demonstrates the syntax, but otherwise makes no sense, and therefore is potentially confusing. It is blatant nonsense to run 5 processes when there are only 3 data to be treated. Let me suggest the following:
from multiprocessing import Pool
import time
def f(x):
time.sleep(1)
return x*x
if __name__ == '__main__':
start_time = time.time()
with Pool(4) as p:
print(p.map(f, range(20)))
print("elapsed wall time: ", time.time()-start_time)
The sleep command makes f representative for a function that takes significant time to execute. Printing the elapsed time shows the user that the 20 calls of f have indeed taken place in parallel. |
|
Date |
User |
Action |
Args |
2017-02-15 22:59:20 | jwuttke | set | recipients:
+ jwuttke, docs@python |
2017-02-15 22:59:20 | jwuttke | set | messageid: <1487199560.37.0.441891248359.issue29575@psf.upfronthosting.co.za> |
2017-02-15 22:59:20 | jwuttke | link | issue29575 messages |
2017-02-15 22:59:20 | jwuttke | create | |
|