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
)
| 197 | |
| 198 | |
| 199 | def 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 | |
| 221 | def future_set_exc_info( |
no outgoing calls
no test coverage detected