9-[多線程] 進程池線程池
阿新 • • 發佈:2018-04-24
span print div 多線程 img inf 每次 col star
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.startpool = ProcessPoolExecutor(4) # 進程池max_workers:4個 for i in range(10): # 總共執行10次,每次4個進程的執行 pool.submit(task, ‘子進程%s‘ % i) print(‘主‘)
2
3
4
5
9-[多線程] 進程池線程池