MCPcopy Index your code
hub / github.com/python/cpython / set_exception

Method set_exception

Lib/asyncio/futures.py:273–294  ·  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

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

Calls 2

__schedule_callbacksMethod · 0.95
exceptionFunction · 0.85