1. 程式人生 > >9-[多線程] 進程池線程池

9-[多線程] 進程池線程池

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.start
pool = ProcessPoolExecutor(4) # 進程池max_workers:4個 for i in range(10): # 總共執行10次,每次4個進程的執行 pool.submit(task, 子進程%s % i) print()

技術分享圖片

2

技術分享圖片

技術分享圖片

3

技術分享圖片

技術分享圖片

4

5

9-[多線程] 進程池線程池