code: def _set_result_from_operation(self):
          
          # This must be done in a lock to prevent the polling thread
          # and main thread from both executing the completion logic
          # at the same time.
          with self._completion_lock:
              # If the operation isn't complete or if the result has already been
              # set, do not call set_result/set_exception again.
              # Note: self._result_set is set to True in set_result and
              # set_exception, in case those methods are invoked directly.
              if not self._operation.done or self._result_set:
                  return
  
              if self._operation.HasField("response"):
                  response = protobuf_helpers.from_any_pb(
                      self._result_type, self._operation.response
                  )
                  self.set_result(response)
              elif self._operation.HasField("error"):
                  exception = exceptions.GoogleAPICallError(
                      self._operation.error.message,
                      errors=(self._operation.error,),
                      response=self._operation,
                  )
                  self.set_exception(exception)
              else:
                  exception = exceptions.GoogleAPICallError(
                      "Unexpected state: Long-running operation had neither "
                      "response nor error set."
                  )
                  self.set_exception(exception)
docs: Set the result or exception from the operation if it is complete.