from multiprocessing import Process
import os
print(os.getpid())
def run_proc(name):
print('Run child process %s (%s)...' % (name, os.getpid()))
if __name__=='__main__':
p = Process(target=run_proc, args=('test',))
p.start()
输出结果:
7196
8232
Run child process test (8232)...
由于没有p.join所以等主进程结束后,子进程自动执行,2比1先打印
子进程相当于运行当前文件,只不过name值变更
这样好理解么?