【问题标题】:With Python's multiprocessing.Pool and map_asynch, how can I get information about the workers?使用 Python 的 multiprocessing.Pool 和 map_asynch,我如何获取有关工作人员的信息?
【发布时间】:2013-06-02 17:20:29
【问题描述】:

在以下程序中如何定期检查:

  • 尚未启动的任务数
  • 当前工作的工人人数
  • 已完成的任务数
  • 它们的状态(如果它们已超时)

代码是:

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()

【问题讨论】:

    标签: python multiprocessing threadpool


    【解决方案1】:

    这是你想要的吗?

     ar._number_left 
    

    【讨论】:

    • 您能否获取有关未能完成的信息(例如超时)?
    猜你喜欢
    • 1970-01-01
    • 2015-07-25
    • 2021-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-23
    • 2023-01-21
    • 2011-07-22
    相关资源
    最近更新 更多