(self, exception)
Mark the future done and set an exception.

        If the future is already done when this method is called, raises
        InvalidStateError.
Mark the future done and set an exception.
Mark the future done and set an exception .
def set_exception(self, exception):
        """Mark the future done and set an exception.

        If the future is already done when this method is called, raises
        InvalidStateError.
        """
        if self._state != _PENDING:
            raise exceptions.InvalidStateError(f'{self._state}: {self!r}')
        if isinstance(exception, type):
            exception = exception()
        if type(exception) is StopIteration:
            raise TypeError("StopIteration interacts badly with generators "
                            "and cannot be raised into a Future")
        self._exception = exception
        self._state = _FINISHED
        self.__schedule_callbacks()
        self.__log_traceback = True
def set_exception ( self , exception ) : if self . _state != _PENDING : raise exceptions . InvalidStateError ( f'{self._state}: {self!r}' ) if isinstance ( exception , type ) : exception = exception ( ) if type ( exception ) is StopIteration : raise TypeError ( "StopIteration interacts badly with generators " "and cannot be raised into a Future" ) self . _exception = exception self . _state = _FINISHED self . __schedule_callbacks ( ) self . __log_traceback = True