From fae28de43aa276f882841853c4a82d570c50a25c 2013-07-15 21:51:05 From: MinRK Date: 2013-07-15 21:51:05 Subject: [PATCH] fix AsyncResult.get_dict for single result avoids issue with LoadBalancedView, client[0], etc. Also cleanup the multiple-key test while I'm there, because it was gross. closes #3646 --- diff --git a/IPython/parallel/client/asyncresult.py b/IPython/parallel/client/asyncresult.py index 52b3d72..557e1c4 100644 --- a/IPython/parallel/client/asyncresult.py +++ b/IPython/parallel/client/asyncresult.py @@ -191,12 +191,17 @@ class AsyncResult(object): """ results = self.get(timeout) + if self._single_result: + results = [results] engine_ids = [ md['engine_id'] for md in self._metadata ] - bycount = sorted(engine_ids, key=lambda k: engine_ids.count(k)) - maxcount = bycount.count(bycount[-1]) - if maxcount > 1: - raise ValueError("Cannot build dict, %i jobs ran on engine #%i"%( - maxcount, bycount[-1])) + + seen = set() + for engine_id in engine_ids: + if engine_id in seen: + raise ValueError("Cannot build dict, %i jobs ran on engine #%i"%( + engine_ids.count(engine_id), engine_id)) + else: + seen.add(engine_id) return dict(zip(engine_ids,results))