python-10多进程

1-多进程(multiprocessing),1个父进程可以有多少子进程

from multiprocessing import Process
import os

def run_proc(name):
    print('Run child process %s (%s)' % (name,os.getpid())) #父进程的ID

if __name__ =='__main__':
    print('Parent process %s. ' % os.getpid())
    p = Process(target=run_proc, args=('test', ))
    print('Child process will start')
    p.start() #开始进程
    p.join() #待子子进程结束
    print('Child process end')

相关推荐