def wait(self, timeout=-1):
        """Wait until the result is available or until `timeout` seconds pass.

        This method always returns None.
        """
        if self._ready:
            self._wait_for_outputs(timeout)
            return
        self._ready = self._client.wait(self.msg_ids, timeout)
        if self._ready:
            try:
                results = list(map(self._client.results.get, self.msg_ids))
                self._result = results
                if self._single_result:
                    r = results[0]
                    if isinstance(r, Exception):
                        raise r
                else:
                    results = error.collect_exceptions(results, self._fname)
                self._result = self._reconstruct_result(results)
            except Exception as e:
                self._exception = e
                self._success = False
            else:
                self._success = True
            finally:
                if timeout is None or timeout < 0:
                    # cutoff infinite wait at 10s
                    timeout = 10
                self._wait_for_outputs(timeout)
                
                if self.owner:
                    
                    self._metadata = [self._client.metadata.pop(mid) for mid in self.msg_ids]
                    [self._client.results.pop(mid) for mid in self.msg_ids]
 def __getitem__(self, key):
     """getitem returns result value(s) if keyed by int/slice, or metadata if key is str.
     """
     if isinstance(key, int):
         self._check_ready()
         return error.collect_exceptions([self._result[key]], self._fname)[0]
     elif isinstance(key, slice):
         self._check_ready()
         return error.collect_exceptions(self._result[key], self._fname)
     elif isinstance(key, string_types):
         # metadata proxy *does not* require that results are done
         self.wait(0)
         values = [ md[key] for md in self._metadata ]
         if self._single_result:
             return values[0]
         else:
             return values
     else:
         raise TypeError("Invalid key type %r, must be 'int','slice', or 'str'"%type(key))
Beispiel #3
0
 def __getitem__(self, key):
     """getitem returns result value(s) if keyed by int/slice, or metadata if key is str.
     """
     if isinstance(key, int):
         self._check_ready()
         return error.collect_exceptions([self._result[key]],
                                         self._fname)[0]
     elif isinstance(key, slice):
         self._check_ready()
         return error.collect_exceptions(self._result[key], self._fname)
     elif isinstance(key, string_types):
         # metadata proxy *does not* require that results are done
         self.wait(0)
         values = [md[key] for md in self._metadata]
         if self._single_result:
             return values[0]
         else:
             return values
     else:
         raise TypeError(
             "Invalid key type %r, must be 'int','slice', or 'str'" %
             type(key))
Beispiel #4
0
 def wait(self, timeout=-1):
     """wait for result to complete."""
     start = time.time()
     if self._ready:
         return
     local_ids = [m for m in self.msg_ids if m in self._client.outstanding]
     local_ready = self._client.wait(local_ids, timeout)
     if local_ready:
         remote_ids = [
             m for m in self.msg_ids if m not in self._client.results
         ]
         if not remote_ids:
             self._ready = True
         else:
             rdict = self._client.result_status(remote_ids,
                                                status_only=False)
             pending = rdict['pending']
             while pending and (timeout < 0
                                or time.time() < start + timeout):
                 rdict = self._client.result_status(remote_ids,
                                                    status_only=False)
                 pending = rdict['pending']
                 if pending:
                     time.sleep(0.1)
             if not pending:
                 self._ready = True
     if self._ready:
         try:
             results = list(map(self._client.results.get, self.msg_ids))
             self._result = results
             if self._single_result:
                 r = results[0]
                 if isinstance(r, Exception):
                     raise r
             else:
                 results = error.collect_exceptions(results, self._fname)
             self._result = self._reconstruct_result(results)
         except Exception as e:
             self._exception = e
             self._success = False
         else:
             self._success = True
         finally:
             self._metadata = [
                 self._client.metadata[mid] for mid in self.msg_ids
             ]
             if self.owner:
                 [self._client.metadata.pop(mid) for mid in self.msg_ids]
                 [self._client.results.pop(mid) for mid in self.msg_ids]
 def wait(self, timeout=-1):
     """wait for result to complete."""
     start = time.time()
     if self._ready:
         return
     local_ids = [m for m in self.msg_ids if m in self._client.outstanding]
     local_ready = self._client.wait(local_ids, timeout)
     if local_ready:
         remote_ids = [m for m in self.msg_ids if m not in self._client.results]
         if not remote_ids:
             self._ready = True
         else:
             rdict = self._client.result_status(remote_ids, status_only=False)
             pending = rdict['pending']
             while pending and (timeout < 0 or time.time() < start+timeout):
                 rdict = self._client.result_status(remote_ids, status_only=False)
                 pending = rdict['pending']
                 if pending:
                     time.sleep(0.1)
             if not pending:
                 self._ready = True
     if self._ready:
         try:
             results = list(map(self._client.results.get, self.msg_ids))
             self._result = results
             if self._single_result:
                 r = results[0]
                 if isinstance(r, Exception):
                     raise r
             else:
                 results = error.collect_exceptions(results, self._fname)
             self._result = self._reconstruct_result(results)
         except Exception as e:
             self._exception = e
             self._success = False
         else:
             self._success = True
         finally:
             self._metadata = [self._client.metadata[mid] for mid in self.msg_ids]
             if self.owner:
                 [self._client.metadata.pop(mid) for mid in self.msg_ids]
                 [self._client.results.pop(mid) for mid in self.msg_ids]
Beispiel #6
0
    def wait(self, timeout=-1):
        """Wait until the result is available or until `timeout` seconds pass.

        This method always returns None.
        """
        if self._ready:
            self._wait_for_outputs(timeout)
            return
        self._ready = self._client.wait(self.msg_ids, timeout)
        if self._ready:
            try:
                results = list(map(self._client.results.get, self.msg_ids))
                self._result = results
                if self._single_result:
                    r = results[0]
                    if isinstance(r, Exception):
                        raise r
                else:
                    results = error.collect_exceptions(results, self._fname)
                self._result = self._reconstruct_result(results)
            except Exception as e:
                self._exception = e
                self._success = False
            else:
                self._success = True
            finally:
                if timeout is None or timeout < 0:
                    # cutoff infinite wait at 10s
                    timeout = 10
                self._wait_for_outputs(timeout)

                if self.owner:

                    self._metadata = [
                        self._client.metadata.pop(mid) for mid in self.msg_ids
                    ]
                    [self._client.results.pop(mid) for mid in self.msg_ids]