date: 2019-06-16 22:35:33
author: headsen chen
notice: personal original
Example code:
import os,time time.sleep(1) from multiprocessing import Process a = 100 print(a,os.getpid(),os.getppid(),"开始执行") def func(i): print("i = %s,子进程id >>> %s,父进程id >>> %s."%(i,os.getpid(),os.getppid())) if __name__ == "__main__": for i in range(3): p=Process(target=func,args=(i,)) p.start() A + = 222 Print (A, " concurrency " ) the time.sleep ( 10 ) Print (A, os.getpid (), os.getppid (), " ends execution " )
Results of the:
" C: \ Program Files \ Python36 \ python.exe " E: / job / Chen Reserve soldiers -L009- Code practice 1.py 100 8656 5412 started 322 concurrent in 544 concurrent in 766 concurrency 10,066,888,656 started 10,052,648,656 start execution 10,059,008,656 started 76,686,565,412 end of the implementation 10,066,888,656 end of the implementation 10,052,648,656 end of the implementation 10,059,008,656 end the execution of i = 0, the child process id >>> 6688, >>> 8656 the parent process the above mentioned id . i = 1, child process id >>> 5264, >>> 8656 the parent process the above mentioned id . i = 2, the child process id >>> 5900, >>> 8656 the parent process the above mentioned id . Process finished with exit code 0