1 #creating multiple processes using the multiprocessing module2 #The Multiprcessing module provides a process class to describe a processing object.3 #When you create a child process, you only need to pass in a parameter that executes functions and functions to complete the creation of a process instance4 #start the process with the start () method5 #use the Join () method to synchronize between processes.6 ImportOS7 fromMultiprocessingImportProcess8 #The Getpid () method in the OS module gets the ID of the current process9 #getppid () method gets the ID of the parent processTen #code to be executed by the child process One defRun_proc (name): A Print('Child Process%s (%s) running .....'%(name, Os.getpid ())) - - if __name__=='__main__': the Print('Parent Process%s'%os.getpid ()) - forIinchRange (5): -p = Process (Target=run_proc, args=(str (i),)) - Print('process would start.') + P.start () - P.join () + Print('process end.')
Creating multiple processes using the multiprocessing module