The multiprocessing library provides the Pool class for simple parallel processing tasks.
The Pool class has the following methods:
- apply(): This blocks until the result is ready.
- apply_async(): This is a variant of the apply() (https://docs.python.org/2/library/functions.html#apply) method, which returns a result object. It is an asynchronous operation that will not lock the main thread until all the child classes are executed.
- map(): This is the parallel equivalent of the built-in map() (https://docs.python.org/2/library/functions.html#map) function. This blocks until the result is ready, and it chops the iterable data in a number of chunks that are submitted to the process pool as separate tasks.
- map_async(): This is a variant of the map() (https://docs.python.org/2/library/multiprocessing.html?highlight=pool%20class#multiprocessing.pool.multiprocessing.Pool.map) method, which returns a result object. If a callback is specified, then it should be callable, which accepts a single argument. When the result becomes ready, a callback is applied to it (unless the call fails). A callback should be completed immediately; otherwise, the thread that handles the results will get blocked.