【问题标题】:With Ipython.parallel, How could i monitor the progress of a task?使用 Ipython.parallel,我如何监控任务的进度?
【发布时间】:2013-04-03 11:06:21
【问题描述】:

这样的东西会很好:

from IPython.parallel import Client
dv=Client()[0]

import time
def waitprogress(n):
  for i in range(n):
    time.sleep(1)
    global progress
    progress=str(i)+'/'+str(n)

dv.block=False
dv.apply(waitprogress,10)

dv['progress']
# the command wait 10 seconds, then returns 9/10

这不起作用,因为 IPython 会等待 dv.apply 结束,然后再搜索远程实例中的进度变量。

SO 的伟大人物有什么想法吗?

【问题讨论】:

    标签: parallel-processing monitoring ipython


    【解决方案1】:

    来自 SO 的回答:Reading the stdout of ipcluster 我找到了使用标准输出的解决方案:

    from IPython.parallel import Client
    c=Client()
    dv=c[0]
    
    import time
    def waitprogress(n):
      for i in range(n):
        time.sleep(1)
        print str(i)+'/'+str(n)
    
    dv.block=False
    res=dv.apply(waitprogress,10)
    
    print c.spin() or c.metadata[res.msg_ids[0]].stdout.split()[-1]
    #1/10
    time.sleep(3)
    print c.spin() or c.metadata[res.msg_ids[0]].stdout.split()[-1]
    #4/10
    

    如果有人有更好的解决方案,那就太好了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-26
      • 1970-01-01
      • 2011-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多