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)

相关文章:

  • 2021-10-09
  • 2022-01-01
  • 2021-06-20
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
  • 2021-05-19
  • 2022-12-23
  • 2021-05-11
相关资源
相似解决方案