Retrieve the result of the future, waiting for it to complete or at
    max *timeout* seconds.

    :param timeout: The number of maximum seconds to wait for the result.
    :param do_raise: Set to False to prevent any of the exceptions below
      to be raised and return :const:`None` instead.
    :raise Cancelled: If the future has been cancelled.
    :raise Timeout: If the *timeout* has been exceeded.
    :raise BaseException: Anything the worker has raised.
    :return: Whatever the worker bound to the future returned.

def result(self, timeout=None, do_raise=True):
    """
    Retrieve the result of the future, waiting for it to complete or at
    max *timeout* seconds.

    :param timeout: The number of maximum seconds to wait for the result.
    :param do_raise: Set to False to prevent any of the exceptions below
      to be raised and return :const:`None` instead.
    :raise Cancelled: If the future has been cancelled.
    :raise Timeout: If the *timeout* has been exceeded.
    :raise BaseException: Anything the worker has raised.
    :return: Whatever the worker bound to the future returned.
    """

    with self._lock:
      self.wait(timeout, do_raise=do_raise)
      if self._exc_info:
        if not do_raise:
          return None
        # Its more important to re-raise the exception from the worker.
        self._exc_retrieved = True
        reraise(*self._exc_info)
      if self._cancelled:
        if not do_raise:
          return None
        raise self.Cancelled()
      return self._result