Show More
@@ -158,6 +158,8 b' class AsyncResult(object):' | |||||
158 | self._success = True |
|
158 | self._success = True | |
159 | finally: |
|
159 | finally: | |
160 | self._metadata = map(self._client.metadata.get, self.msg_ids) |
|
160 | self._metadata = map(self._client.metadata.get, self.msg_ids) | |
|
161 | self._wait_for_outputs() | |||
|
162 | ||||
161 |
|
163 | |||
162 |
|
164 | |||
163 | def successful(self): |
|
165 | def successful(self): | |
@@ -424,6 +426,19 b' class AsyncResult(object):' | |||||
424 | if self.pyout is not None: |
|
426 | if self.pyout is not None: | |
425 | display(self.get()) |
|
427 | display(self.get()) | |
426 |
|
428 | |||
|
429 | def _wait_for_outputs(self, timeout=-1): | |||
|
430 | """wait for the 'status=idle' message that indicates we have all outputs | |||
|
431 | """ | |||
|
432 | if not self._success: | |||
|
433 | # don't wait on errors | |||
|
434 | return | |||
|
435 | tic = time.time() | |||
|
436 | while not all(md['outputs_ready'] for md in self._metadata): | |||
|
437 | time.sleep(0.01) | |||
|
438 | self._client._flush_iopub(self._client._iopub_socket) | |||
|
439 | if timeout >= 0 and time.time() > tic + timeout: | |||
|
440 | break | |||
|
441 | ||||
427 | @check_ready |
|
442 | @check_ready | |
428 | def display_outputs(self, groupby="type"): |
|
443 | def display_outputs(self, groupby="type"): | |
429 | """republish the outputs of the computation |
|
444 | """republish the outputs of the computation | |
@@ -453,8 +468,6 b' class AsyncResult(object):' | |||||
453 | several plots, and you would like to see all of the first |
|
468 | several plots, and you would like to see all of the first | |
454 | plots together, then all of the second plots, and so on. |
|
469 | plots together, then all of the second plots, and so on. | |
455 | """ |
|
470 | """ | |
456 | # flush iopub, just in case |
|
|||
457 | self._client._flush_iopub(self._client._iopub_socket) |
|
|||
458 | if self._single_result: |
|
471 | if self._single_result: | |
459 | self._display_single_result() |
|
472 | self._display_single_result() | |
460 | return |
|
473 | return | |
@@ -619,7 +632,6 b' class AsyncMapResult(AsyncResult):' | |||||
619 | yield r |
|
632 | yield r | |
620 |
|
633 | |||
621 |
|
634 | |||
622 |
|
||||
623 | class AsyncHubResult(AsyncResult): |
|
635 | class AsyncHubResult(AsyncResult): | |
624 | """Class to wrap pending results that must be requested from the Hub. |
|
636 | """Class to wrap pending results that must be requested from the Hub. | |
625 |
|
637 | |||
@@ -627,6 +639,10 b' class AsyncHubResult(AsyncResult):' | |||||
627 | so use `AsyncHubResult.wait()` sparingly. |
|
639 | so use `AsyncHubResult.wait()` sparingly. | |
628 | """ |
|
640 | """ | |
629 |
|
641 | |||
|
642 | def _wait_for_outputs(self, timeout=None): | |||
|
643 | """no-op, because HubResults are never incomplete""" | |||
|
644 | return | |||
|
645 | ||||
630 | def wait(self, timeout=-1): |
|
646 | def wait(self, timeout=-1): | |
631 | """wait for result to complete.""" |
|
647 | """wait for result to complete.""" | |
632 | start = time.time() |
|
648 | start = time.time() |
@@ -184,6 +184,7 b' class Metadata(dict):' | |||||
184 | 'stdout' : '', |
|
184 | 'stdout' : '', | |
185 | 'stderr' : '', |
|
185 | 'stderr' : '', | |
186 | 'outputs' : [], |
|
186 | 'outputs' : [], | |
|
187 | 'outputs_ready' : False, | |||
187 | } |
|
188 | } | |
188 | self.update(md) |
|
189 | self.update(md) | |
189 | self.update(dict(*args, **kwargs)) |
|
190 | self.update(dict(*args, **kwargs)) | |
@@ -880,6 +881,10 b' class Client(HasTraits):' | |||||
880 | md['outputs'].append(content) |
|
881 | md['outputs'].append(content) | |
881 | elif msg_type == 'pyout': |
|
882 | elif msg_type == 'pyout': | |
882 | md['pyout'] = content |
|
883 | md['pyout'] = content | |
|
884 | elif msg_type == 'status': | |||
|
885 | # idle message comes after all outputs | |||
|
886 | if content['execution_state'] == 'idle': | |||
|
887 | md['outputs_ready'] = True | |||
883 | else: |
|
888 | else: | |
884 | # unhandled msg_type (status, etc.) |
|
889 | # unhandled msg_type (status, etc.) | |
885 | pass |
|
890 | pass |
General Comments 0
You need to be logged in to leave comments.
Login now