def result(self, timeout=None): """Returns the result of the call that the future represents. :param timeout: The number of seconds to wait for the result if the future has not been completed. None, the default, sets no limit. :returns: The result of the call that the future represents. :raises: TimeoutError: If the timeout is reached before the future ends execution. :raises: Exception: If the call raises the Exception. """ with self.__condition: if self.__state == FINISHED: return self.__get__result() lock = get_lock() if lock is not None: lock.release() self.__condition.wait(timeout) if lock is not None: lock.acquire() if self.__state == FINISHED: return self.__get__result() else: raise TimeoutError('Future: %r' % self.__method)
def exception(self, timeout=None): """Return a exception raised by the call that the future represents. :param timeout: The number of seconds to wait for the exception if the future has not been completed. None, the default, sets no limit. :returns: The exception raised by the call that the future represents or None if the call completed without raising. :raises: TimeoutError: If the timeout is reached before the future ends execution. """ # with self.__condition: if self.__state == FINISHED: return self.__exception self.__condition.wait(timeout) if self.__state == FINISHED: return self.__exception else: raise TimeoutError('Future: %r' % self.__method)