multiprocessing
from multiprocessing import Process import time def f(name): time.sleep(2) print('hello',name) if __name__ == '__main__': p1 = Process(target=f,args = ('bob',)) p2 = Process(target=f,args=('john',)) p1.start() p2.start() p1.join()
显示进程ID
# !/usr/bin/env python # -*- coding:utf-8 -*- from multiprocessing import Process import os def info(title): print(title) print('module name:', __name__) print('parent process:', os.getppid()) # 父进程ID print('process id:', os.getpid()) #自己的进程ID print(" ") def f(name): info('