python3 线程池

from concurrent.futures import ThreadPoolExecutor,ProcessPoolExecutor #线程池,进程池
import threading,time
 
def test(arg):
    print(arg,threading.current_thread().name)
    time.sleep(1)
 
if __name__ == "__main__":
    thread_pool = ThreadPoolExecutor(5) #定义5个线程执行此任务
    process_pool = ProcessPoolExecutor(5) #定义5个进程
    for i in range(20):
        thread_pool.submit(test,i)
        #process_pool.submit(test,i)
posted @ 2020-12-23 10:38  总得前行  阅读(424)  评论(0编辑  收藏  举报