Each process subclass is represented by a class that extends the Process class and overrides the run() method. This method is the starting point of Process:
class MyProcess (multiprocessing.Process):
def run(self):
print ('called run method in process: %s' %self.name)
return
In the main program, we create several objects of the MyProcess() type. The execution of the thread begins when the start() method is called:
p = MyProcess()
p.start()
The join() command just handles the termination of processes. To run the script from Command Prompt, type the following command:
> python process_in_subclass.py
The output looks like this:
called run method by MyProcess-1
called run method by MyProcess-2
called run method by MyProcess-3
called run method by MyProcess-4
called run method by MyProcess-5
called run method by MyProcess-6
called run method by MyProcess-7
called run method by MyProcess-8
called run method by MyProcess-9
called run method by MyProcess-10