使用:from concurrent.futures import ProcessPoolExecutor
from concurrent.futures import ProcessPoolExecutor import time,random,os def task(name): print('%s%s is running' %(name,os.getpid())) time.sleep(random.randint(1,3)) if __name__ == '__main__': print(os.cpu_count()) #查看cpu的个数 p=ProcessPoolExecutor(4) #开启进程池 for i in range(10): p.submit(task,'进程pid:') print("主") 结果: 主 进程pid:3480 is running 进程pid:12104 is running 进程pid:10252 is running 进程pid:12000 is running 进程pid:3480 is running 进程pid:12104 is running 进程pid:10252 is running 进程pid:12000 is running 进程pid:3480 is running 进程pid:12104 is running