multiprocessing包是Python中的多进程管理包。
与threading.Thread类似,它可以利用multiprocessing.Process对象来创建一个进程
#coding=utf-8 import time import multiprocessing import os def test_time(x,y,z): i=1; sum=0; while i< 10: sum+=x*y*z; x+=1; y+=1; z+=1; i+=1; time.sleep(2); return sum; process={}; x=1; y=2; z=3; exit_code={}; for i in range(1,11): mult_test = multiprocessing.Process(target=test_time,args=(x,y,z)); mult_test.start(); process[(x,y,z)]=mult_test; exit_code[(x,y,z)]=66; time.sleep(1); x+=1; y+=1; z+=1; while True: ALLDONE=0; time.sleep(1); os.system("clear"); for key,val in process.items(): if val.exitcode==0: exit_code[key]=0; print_str="%-20s计算结束" % str(key); print(print_str); else: print_str="%-20s还在计算中" % str(key); print(print_str); for value in exit_code.values(): ALLDONE+=value; if ALLDONE ==0: os.system("clear"); print("计算结束"); break;