multiprocessing module can be used to quickly parallelize simple tasks by spawning several processes. Its interface is easy-to-use and includes several utilities to handle task submission and synchronization.
You can create a process that runs independently by subclassing
multiprocessing.Process. You can extend the
__init__ method to initialize resources and you can write the portion of the code destined to the subprocess by implementing a
Process.run method. In the following code, we define a process that will wait for one second and print its assigned
import multiprocessing import time class Process(multiprocessing.Process): def __init__(self, id): super(Process, self).__init__() ...