user32882
user32882

Reputation: 5877

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

Upvotes: 0

Views: 17

Answers (1)

llllllllll
llllllllll

Reputation: 16404

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.

Upvotes: 1

Related Questions