python线程池/进程池创建

进程池

import time
from concurrent.futures import ProcessPoolExecutor


def task(arg):
    time.sleep(2)
    print(arg)
    

if __name__ == '__main__':
    pool = ProcessPoolExecutor(5)
    for i in range(20):
        pool.submit(task, i)

线程池

import time
from concurrent.futures import ThreadPoolExecutor


def task(arg):
    time.sleep(2)
    print(arg)


if __name__ == '__main__':
    pool = ThreadPoolExecutor(5)
    for i in range(20):
        pool.submit(task, i)

猜你喜欢

转载自www.cnblogs.com/apollo1616/p/10351481.html