1 import multiprocessing 2 import time,threading 3 4 def threading_run(): 5 print(threading.get_ident())#获取线程ID 6 7 def run(name): 8 time.sleep(2) 9 print('hello', name) 10 t = threading.Thread(target=threading_run,)#每个进程下创建一个线程 11 t.start() 12 13 if __name__ == '__main__': 14 for i in range(10):#10个线程 15 p = multiprocessing.Process(target=run, args=('bob%s'%i,)) 16 p.start() 17 # p.join()
获取进程ID:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 from multiprocessing import Process 2 import os 3 4 5 def info(title): 6 print(title) 7 print('module name:', __name__) 8 print('parent process:', os.getppid())#获取父进程ID 9 print('process id:', os.getpid())#获取自己进程ID 10 print(" ") 11 12 13 def f(name): 14 info('