Skip to Content
Modern Python Standard Library Cookbook
book

Modern Python Standard Library Cookbook

by Alessandro Molina
August 2018
Intermediate to advanced
366 pages
10h 14m
English
Packt Publishing
Content preview from Modern Python Standard Library Cookbook

How it works...

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced Python Development: Using Powerful Language Features in Real-World Applications

Advanced Python Development: Using Powerful Language Features in Real-World Applications

Matthew Wilkes

Publisher Resources

ISBN: 9781788830829Supplemental Content