August 2018
Intermediate to advanced
366 pages
10h 14m
English
When multiprocessing.Pool is created, a number of processes equal to the number of cores on the system (as stated by os.cpu_count()) is created through os.fork or by spawning a new Python interpreter, depending on what's supported by the underlying system:
>>> pool = Pool()
Once the new processes are started, they will all do the same thing: execute the worker function that loops forever consuming from the queue of jobs that were sent to Pool and running them one by one.
This means that if we create a Pool of two processes, we will have two workers. As soon as we ask Pool to perform something (through Pool.apply_async, Pool.map, or any other method), the jobs (functions and its arguments) are placed in multiprocessing.SimpleQueue ...