# 关于多进程的一些理解
#利用multiprocessing模块里面的Process类(这里无论是Python2还是3都是如此)
from multiprocessing import Process
import time,os
def run_process(name):
print(os.getpid(),name)
if __name__ == '__main__':
print('start',os.getpid())
for i in range(5):
print(os.getpid())
p = Process(target = run_process,args = (i,))
print('------------------')
p.start()
#time.sleep(1)
print('...............')
p.join()
print('end')
上面这段代码运行结果:
start 1188
1188
------------------
...............
1188
------------------
...............
1188