进程池

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)