Pythonのスレッドプール(部)

Pythonのスレッドプール(部)

concurrent.futures インポートThreadPoolExecutor、ProcessPoolExecutorの

インポートOS、時間、ランダム
 デフタスク(n)を:
     印刷' %sがruningてれる'%のos.getpid())
    time.sleep(random.randint( 1,3 ))
     戻り N ** 2 なら__name__ == ' __main__ ' 
    エグゼキュータ = ProcessPoolExecutor(max_workers = 3 
    先物 = []
     のための I における範囲(11 ):
        将来 =

 

executor.submit(タスク、I)
        futures.append(未来)
    executor.shutdown(真の)
    プリント' +++> ' のための将来における先物:
         プリント(future.result())

 

おすすめ

転載: www.cnblogs.com/xiangsikai/p/11238085.html