线程ThreadPoolExecutor与进程ProcessPoolExecutor
Posted lhqlhq
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了线程ThreadPoolExecutor与进程ProcessPoolExecutor相关的知识,希望对你有一定的参考价值。
###################### 线程池 ############ from concurrent.futures import ThreadPoolExecutor import time def task(arg): print(arg) time.sleep(1) pool = ThreadPoolExecutor(5) for i in range(50): pool.submit(task,i) ################################################# ############################# 进程池 ################# from concurrent.futures import ProcessPoolExecutor import time def task(arg): print(arg) time.sleep(1) if __name__ == ‘__main__‘: pool = ProcessPoolExecutor(3) for i in range(50): pool.submit(task,i)
以上是关于线程ThreadPoolExecutor与进程ProcessPoolExecutor的主要内容,如果未能解决你的问题,请参考以下文章
线程池和进程池的通用写法 ProcessPoolExecutor 和 ThreadPoolExecutor
进程池和线程池 concurrent.futures import ProcessPoolExecutor,ThreadPoolExecutor