An overview of the multiprocessing module
The multiprocessing
module is one of the most commonly used implementations of multiprocessing programming in Python. It offers methods to spawn and interact with processes using an API similar to the threading
module (as we saw with the start()
and join()
methods in the preceding example). According to its documentation website, the module allows both local and remote concurrency and effectively avoids the global interpreter lock (GIL) in Python (which we will discuss in more detail later in Chapter 22, The Global Interpreter Lock) by using subprocesses instead of threads.
The process class
In the multiprocessing
module, processes are typically spawned and managed through the Process
class. Each Process
object represents an activity that executes in a separate process. Conveniently, the Process
class has equivalent methods and APIs that can be found in the threading.Thread
class.
Specifically, utilizing an object-oriented programming approach, the...