python 5. 线程池 与 进程池

 

1. 线程池使用   

注意 : ProcessPoolExecutor 进程池 不好用  同进程一样 

 

from concurrent.futures import ThreadPoolExecutor,ProcessPoolExecutor

def fn(name):
    for i in range(10):
        print(name, i)

if __name__ == '__main__':

    #创建线程池
    with ThreadPoolExecutor(10) as t:
        for i in range(10):
            t.submit(fn, name=f'线程{i}')
    print('over!')

 

posted @ 2022-04-28 13:16  我在春天等伱  阅读(51)  评论(0)    收藏  举报