监控ipyparallel完成的状态

时间:2015-10-11 03:00:56

标签: ipython-notebook ipython-parallel

我有一个需要一段时间来计算的函数,并且必须使用两个不同的参数迭代> 20k次:

from ipyparallel import Client
import numpy as np

m_array = np.arange(0, 101, 1)
s_array = np.arange(0, 201, 1)
rc = Client()
rc[:].push(dict(stuff=stuff))
view = rc.load_balanced_view()
async_results = []

for m in m_array:
    for s in s_array:
        chi = view.apply_async(run_simulation, m=m, s=s)
        async_results.append(chi)
rc.wait(async_results)
results = [ar.get() for ar in async_results]

我看到有wait_interactive方法可用,但我无法弄清楚如何使用它。在某个给定的时间间隔内打印状态更新的最佳方法是什么?

更新

我添加了all_ids列表和get_result().wait_interative()方法。

async_results = []
all_ids = []
for m in m_array:
    for s in s_array:
        chi = view.apply_async(run_simulation, m=m, s=s)
        async_results.append(chi)
        all_ids.extend(chi.msg_ids)
rc.get_result(all_ids).wait_interactive()
rc.wait(async_results)
results = [ar.get() for ar in async_results]

这会按预期生成定期状态更新,但现在会生成回溯。

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-36-85db6ca605cd> in <module>()
    220 rc.get_result(all_ids).wait_interactive()
    221 rc.wait(async_results)
--> 222 results = [ar.get() for ar in async_results]
223 results = np.array(results)
224 results.shape = (len(m_array), len(s_array))

//anaconda/lib/python2.7/site-packages/ipyparallel/client/asyncresult.pyc in get(self, timeout)
     95         by get() inside a `RemoteError`.
     96         """
---> 97         if not self.ready():
     98             self.wait(timeout)
     99 

//anaconda/lib/python2.7/site-packages/ipyparallel/client/asyncresult.pyc in ready(self)
    113         """Return whether the call has completed."""
    114         if not self._ready:
--> 115             self.wait(0)
    116         elif not self._outputs_ready:
    117             self._wait_for_outputs(0)

//anaconda/lib/python2.7/site-packages/ipyparallel/client/asyncresult.pyc in     wait(self, timeout)
    152                 if self.owner:
    153 
--> 154                     self._metadata = [self._client.metadata.pop(mid) for mid in self.msg_ids]
155                     [self._client.results.pop(mid) for mid in self.msg_ids]
    156 

KeyError: '884328c8-d768-48d5-b477-a256ebaea7a9'

ar.get()方法找到之前,消息ID或结果是否被清除?

1 个答案:

答案 0 :(得分:3)

wait_interactive是AsyncResult对象的一个​​方法。它很快就会成为客户端的一种方法,但目前还不是。这意味着要使用wait_interactive,您需要构建一个包含所有结果的AsyncResult。最简单的方法是维护与您的请求相对应的所有msg_ids的单个列表:

all_ids = []
for m in m_array:
    for s in s_array:
        chi = view.apply_async(run_simulation, m=m, s=s)
        async_results.append(chi)
        all_ids.extend(chi.msg_ids)

rc.get_result(all_ids, owner=False).wait_interactive()