MCPcopy Index your code
hub / github.com/RustPython/RustPython / set_exception

Method set_exception

Lib/asyncio/futures.py:269–290  ·  view source on GitHub ↗

Mark the future done and set an exception. If the future is already done when this method is called, raises InvalidStateError.

(self, exception)

Source from the content-addressed store, hash-verified

267 self.__schedule_callbacks()
268
269 def set_exception(self, exception):
270 """Mark the future done and set an exception.
271
272 If the future is already done when this method is called, raises
273 InvalidStateError.
274 """
275 if self._state != _PENDING:
276 raise exceptions.InvalidStateError(f'{self._state}: {self!r}')
277 if isinstance(exception, type):
278 exception = exception()
279 if isinstance(exception, StopIteration):
280 new_exc = RuntimeError("StopIteration interacts badly with "
281 "generators and cannot be raised into a "
282 "Future")
283 new_exc.__cause__ = exception
284 new_exc.__context__ = exception
285 exception = new_exc
286 self._exception = exception
287 self._exception_tb = exception.__traceback__
288 self._state = _FINISHED
289 self.__schedule_callbacks()
290 self.__log_traceback = True
291
292 def __await__(self):
293 if not self.done():

Calls 3

__schedule_callbacksMethod · 0.95
isinstanceFunction · 0.85
exceptionFunction · 0.50