How to do it...

Just consider a very simple example, as follows:

  1. Import the relevant library first:
import multiprocessing
  1. 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

  1. 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()
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.137.164