线程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)

猜你喜欢

转载自www.cnblogs.com/lhqlhq/p/9246364.html