Show More
@@ -267,6 +267,41 b' class AsyncResult(object):' | |||||
267 | # Sugar methods and attributes |
|
267 | # Sugar methods and attributes | |
268 | #------------------------------------- |
|
268 | #------------------------------------- | |
269 |
|
269 | |||
|
270 | def timedelta(self, start, end, start_key=min, end_key=max): | |||
|
271 | """compute the difference between two sets of timestamps | |||
|
272 | ||||
|
273 | The default behavior is to use the earliest of the first | |||
|
274 | and the latest of the second list, but this can be changed | |||
|
275 | by passing a different | |||
|
276 | ||||
|
277 | Parameters | |||
|
278 | ---------- | |||
|
279 | ||||
|
280 | start : one or more datetime objects (e.g. ar.submitted) | |||
|
281 | end : one or more datetime objects (e.g. ar.received) | |||
|
282 | start_key : callable | |||
|
283 | Function to call on `start` to extract the relevant | |||
|
284 | entry [defalt: min] | |||
|
285 | end_key : callable | |||
|
286 | Function to call on `end` to extract the relevant | |||
|
287 | entry [default: max] | |||
|
288 | ||||
|
289 | Returns | |||
|
290 | ------- | |||
|
291 | ||||
|
292 | dt : float | |||
|
293 | The time elapsed (in seconds) between the two selected timestamps. | |||
|
294 | """ | |||
|
295 | if not isinstance(start, datetime): | |||
|
296 | # handle single_result AsyncResults, where ar.stamp is single object, | |||
|
297 | # not a list | |||
|
298 | start = start_key(start) | |||
|
299 | if not isinstance(end, datetime): | |||
|
300 | # handle single_result AsyncResults, where ar.stamp is single object, | |||
|
301 | # not a list | |||
|
302 | end = end_key(end) | |||
|
303 | return (end - start).total_seconds() | |||
|
304 | ||||
270 | @property |
|
305 | @property | |
271 | def progress(self): |
|
306 | def progress(self): | |
272 | """the number of tasks which have been completed at this point. |
|
307 | """the number of tasks which have been completed at this point. | |
@@ -313,10 +348,11 b' class AsyncResult(object):' | |||||
313 | Only reliable if Client was spinning/waiting when the task finished, because |
|
348 | Only reliable if Client was spinning/waiting when the task finished, because | |
314 | the `received` timestamp is created when a result is pulled off of the zmq queue, |
|
349 | the `received` timestamp is created when a result is pulled off of the zmq queue, | |
315 | which happens as a result of `client.spin()`. |
|
350 | which happens as a result of `client.spin()`. | |
|
351 | ||||
|
352 | For similar comparison of other timestamp pairs, check out AsyncResult.timedelta. | |||
|
353 | ||||
316 | """ |
|
354 | """ | |
317 | received = max([ md['received'] for md in self._metadata ]) |
|
355 | return self.timedelta(self.submitted, self.received) | |
318 | submitted = min([ md['submitted'] for md in self._metadata ]) |
|
|||
319 | return (received - submitted).total_seconds() |
|
|||
320 |
|
356 | |||
321 | def wait_interactive(self, interval=1., timeout=None): |
|
357 | def wait_interactive(self, interval=1., timeout=None): | |
322 | """interactive wait, printing progress at regular intervals""" |
|
358 | """interactive wait, printing progress at regular intervals""" |
General Comments 0
You need to be logged in to leave comments.
Login now