1
# 进程池,线程池 from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor import os import time def task(name): print(‘%s is running 《pid: %s》‘ % (name, os.getpid())) time.sleep(2) if __name__ == ‘__main__‘: # p = Process(target=task, args=(‘子‘,)) # p.start pool = ProcessPoolExecutor(4) # 进程池max_workers:4个 for i in range(10): # 总共执行10次,每次4个进程的执行 pool.submit(task, ‘子进程%s‘ % i) print(‘主‘)
2
3
4
5
原文地址:https://www.cnblogs.com/venicid/p/8923528.html
时间: 2024-10-10 08:08:59