• Index

线程池

Reads: 2018 Edit

from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor  # 线程池,进程池
import threading, time

def test(arg):
    #print(arg, threading.current_thread().name)
    print('thread_name={thread_name},arg={arg}'.format(thread_name=threading.current_thread().name,arg=arg) )
    time.sleep(2)

if __name__ == "__main__":
    thread_pool = ThreadPoolExecutor(5)  # 定义5个线程执行此任务

    for i in range(20):
        thread_pool.submit(test, i)




Comments

Make a comment

www.ultrapower.com ,王硕的博客,专注于研究互联网产品和技术,提供中文精品教程。 本网站与其它任何公司及/或商标无任何形式关联或合作。
  • Index
aaaaa