Show More
@@ -83,7 +83,7 b' class AsyncResult(object):' | |||||
83 | self._tracker = tracker |
|
83 | self._tracker = tracker | |
84 | self._ready = False |
|
84 | self._ready = False | |
85 | self._success = None |
|
85 | self._success = None | |
86 | self._metadata = None |
|
86 | self._metadata = [ self._client.metadata.get(id) for id in self.msg_ids ] | |
87 | if len(msg_ids) == 1: |
|
87 | if len(msg_ids) == 1: | |
88 | self._single_result = not isinstance(targets, (list, tuple)) |
|
88 | self._single_result = not isinstance(targets, (list, tuple)) | |
89 | else: |
|
89 | else: | |
@@ -126,6 +126,10 b' class AsyncResult(object):' | |||||
126 | else: |
|
126 | else: | |
127 | raise error.TimeoutError("Result not ready.") |
|
127 | raise error.TimeoutError("Result not ready.") | |
128 |
|
128 | |||
|
129 | def _check_ready(self): | |||
|
130 | if not self.ready(): | |||
|
131 | raise error.TimeoutError("Result not ready.") | |||
|
132 | ||||
129 | def ready(self): |
|
133 | def ready(self): | |
130 | """Return whether the call has completed.""" |
|
134 | """Return whether the call has completed.""" | |
131 | if not self._ready: |
|
135 | if not self._ready: | |
@@ -157,9 +161,8 b' class AsyncResult(object):' | |||||
157 | else: |
|
161 | else: | |
158 | self._success = True |
|
162 | self._success = True | |
159 | finally: |
|
163 | finally: | |
160 | self._metadata = map(self._client.metadata.get, self.msg_ids) |
|
164 | ||
161 | self._wait_for_outputs(10) |
|
165 | self._wait_for_outputs(10) | |
162 |
|
||||
163 |
|
166 | |||
164 |
|
167 | |||
165 | def successful(self): |
|
168 | def successful(self): | |
@@ -192,14 +195,13 b' class AsyncResult(object):' | |||||
192 |
|
195 | |||
193 | @property |
|
196 | @property | |
194 | def result(self): |
|
197 | def result(self): | |
195 |
"""result property wrapper for `get(timeout= |
|
198 | """result property wrapper for `get(timeout=-1)`.""" | |
196 | return self.get() |
|
199 | return self.get() | |
197 |
|
200 | |||
198 | # abbreviated alias: |
|
201 | # abbreviated alias: | |
199 | r = result |
|
202 | r = result | |
200 |
|
203 | |||
201 | @property |
|
204 | @property | |
202 | @check_ready |
|
|||
203 | def metadata(self): |
|
205 | def metadata(self): | |
204 | """property for accessing execution metadata.""" |
|
206 | """property for accessing execution metadata.""" | |
205 | if self._single_result: |
|
207 | if self._single_result: | |
@@ -238,15 +240,17 b' class AsyncResult(object):' | |||||
238 | # dict-access |
|
240 | # dict-access | |
239 | #------------------------------------- |
|
241 | #------------------------------------- | |
240 |
|
242 | |||
241 | @check_ready |
|
|||
242 | def __getitem__(self, key): |
|
243 | def __getitem__(self, key): | |
243 | """getitem returns result value(s) if keyed by int/slice, or metadata if key is str. |
|
244 | """getitem returns result value(s) if keyed by int/slice, or metadata if key is str. | |
244 | """ |
|
245 | """ | |
245 | if isinstance(key, int): |
|
246 | if isinstance(key, int): | |
|
247 | self._check_ready() | |||
246 | return error.collect_exceptions([self._result[key]], self._fname)[0] |
|
248 | return error.collect_exceptions([self._result[key]], self._fname)[0] | |
247 | elif isinstance(key, slice): |
|
249 | elif isinstance(key, slice): | |
|
250 | self._check_ready() | |||
248 | return error.collect_exceptions(self._result[key], self._fname) |
|
251 | return error.collect_exceptions(self._result[key], self._fname) | |
249 | elif isinstance(key, basestring): |
|
252 | elif isinstance(key, basestring): | |
|
253 | # metadata proxy *does not* require that results are done | |||
250 | values = [ md[key] for md in self._metadata ] |
|
254 | values = [ md[key] for md in self._metadata ] | |
251 | if self._single_result: |
|
255 | if self._single_result: | |
252 | return values[0] |
|
256 | return values[0] |
General Comments 0
You need to be logged in to leave comments.
Login now