python线程池/进程池创建

进程池import timefrom concurrent.futures import ProcessPoolExecutordef 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 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)

本文标题为:python线程池/进程池创建

基础教程推荐