Just consider a very simple example, as follows:
- Import the relevant library first:
import multiprocessing
- Then, define a subclass, MyProcess, overriding only the run method, which returns the process' name:
class MyProcess(multiprocessing.Process):
def run(self):
print ('called run method by %s' %self.name)
return
- In the main program, we define a subclass of 10 processes:
if __name__ == '__main__':
for i in range(10):
process = MyProcess()
process.start()
process.join()