Python多线程多进程池

Python多线程多进程池

from concurrent.futures import ThreadPoolExecutor,ProcessPoolExecutor #线程池,进程池
import threading,time
 
def test(i):
    print(i,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)

你可能感兴趣的:(多线程,多进程)