MCPcopy
hub / github.com/tornadoweb/tornado / future_set_exception_unless_cancelled

Function future_set_exception_unless_cancelled

tornado/concurrent.py:199–218  ·  view source on GitHub ↗

Set the given ``exc`` as the `Future`'s exception. If the Future is already canceled, logs the exception instead. If this logging is not desired, the caller should explicitly check the state of the Future and call ``Future.set_exception`` instead of this wrapper. Avoids ``async

(
    future: "Union[futures.Future[_T], Future[_T]]", exc: BaseException
)

Source from the content-addressed store, hash-verified

197
198
199def future_set_exception_unless_cancelled(
200 future: "Union[futures.Future[_T], Future[_T]]", exc: BaseException
201) -> None:
202 """Set the given ``exc`` as the `Future`'s exception.
203
204 If the Future is already canceled, logs the exception instead. If
205 this logging is not desired, the caller should explicitly check
206 the state of the Future and call ``Future.set_exception`` instead of
207 this wrapper.
208
209 Avoids ``asyncio.InvalidStateError`` when calling ``set_exception()`` on
210 a cancelled `asyncio.Future`.
211
212 .. versionadded:: 6.0
213
214 """
215 if not future.cancelled():
216 future.set_exception(exc)
217 else:
218 app_log.error("Exception after Future was cancelled", exc_info=exc)
219
220
221def future_set_exc_info(

Callers 3

handle_responseMethod · 0.90
callbackMethod · 0.90
future_set_exc_infoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected