简体   繁体   中英

Argument to pool function in multiprocessing module in python

In the python docs for the multiprocessing module the very first example is about the Pool command.

from multiprocessing import Pool

def f(x):
    return x*x

if __name__ == '__main__':
    with Pool(5) as p:
        print(p.map(f, [1, 2, 3]))

This script is used to demonstrate how the Pool method can be used to run the same function in parallel for a series of possible arguments.

They do not, however explain or provide the arguments to the Pool method, which in this case equals 5 .

What is that argument? Why is it 5 in this case? Does it have something to do with the number of allowed processes at a given time?

Thanks

You are not reading the documentation of Pool , you are reading just a simple example.

The real documentation of Pool is here , where the meaning of the number is clearly explained:

processes is the number of worker processes to use. If processes is None then the number returned by os.cpu_count() is used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM