gpt4 book ai didi

python - 使用 Python 的 multiprocessing.Pool 和 map_asynch,如何获取有关工作人员的信息?

转载 作者:太空宇宙 更新时间:2023-11-04 06:14:05 25 4
gpt4 key购买 nike

在下面的程序中,我如何定期检查:

  • 尚未开始的任务数
  • 当前工作的 worker 数
  • 已完成的任务数
  • 他们的状态(如果他们超时)

代码是:

from multiprocessing import Pool
import time

def f(x):
time.sleep(x)
return x*x

if __name__ == '__main__':
pool = Pool(processes=4) # start 4 worker processes

ar = pool.map_async(f, range(10)) # prints "[0, 1, 4,..., 81]"
pool.close()
pool.join()
ar.wait()
print ar.get()

最佳答案

这是你想要的吗?

 ar._number_left 

关于python - 使用 Python 的 multiprocessing.Pool 和 map_asynch,如何获取有关工作人员的信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16966514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com