How to use a process pool
The multiprocessing library provides the Pool class for simple parallel processing tasks. The Pool class has the following methods:
apply(): It blocks until the result is ready.apply_async(): This is a variant of theapply()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 themap()built-in function. It blocks until the result is ready, this method chops the iterable data in a number of chunks that submits to the process pool as separate tasks.map_async(): This is a variant of themap()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 failed). A callback should be completed immediately; otherwise, the thread that handles the results will get blocked.
How to do it…
This example...