[issue29575] doc 17.2.1: basic Pool example is too basic

Joachim report at bugs.python.org
Wed Feb 15 17:59:20 EST 2017


New submission from Joachim:

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.

----------
assignee: docs at python
components: Documentation
messages: 287895
nosy: docs at python, j5w6
priority: normal
severity: normal
status: open
title: doc 17.2.1: basic Pool example is too basic
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29575>
_______________________________________


More information about the Python-bugs-list mailing list