.更新版进程池与进程池比较

 

from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
import os, time

def func(i):
    print('Process', i, os.getpid())
    time.sleep(0.1)
    print("Process..end")
    return 88899

 

# (1)ProcessPoolExcutor 进程池的基本使用(改良版)

相对于旧版的进程池,

一定会等待子进程全部执行完毕之后,再终止程序,相当于过去的Process流程

shutdown 相当于Process里面的join

 

if __name__ == "__main__":
    # (1)ProcessPoolExecutor() <==> Pool()
    p = ProcessPoolExecutor(5)
    # (2)submit() <==> apply_async()
    res = p.submit(func, 55)
    # (3)result() <==> get()
    res = res.result()
    print(res) #
    # (4)shutdown <==> close + join
    #p.shutdown()
    print("主进程执行结束...")
View Code

相关文章:

  • 2022-12-23
  • 2022-02-01
  • 2021-09-04
  • 2022-12-23
  • 2022-12-23
  • 2021-05-19
  • 2021-12-04
  • 2022-12-23
猜你喜欢
  • 2021-12-28
  • 2022-12-23
  • 2021-06-07
  • 2022-12-23
  • 2022-12-23
  • 2021-04-16
  • 2021-05-18
相关资源
相似解决方案