diff options
Diffstat (limited to 'Lib/asyncio/timeouts.py')
-rw-r--r-- | Lib/asyncio/timeouts.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/Lib/asyncio/timeouts.py b/Lib/asyncio/timeouts.py index 2c5dd29..e6f5100 100644 --- a/Lib/asyncio/timeouts.py +++ b/Lib/asyncio/timeouts.py @@ -110,10 +110,15 @@ class Timeout: self._state = _State.EXPIRED if self._task.uncancel() <= self._cancelling and exc_type is not None: + # Since there are no new cancel requests, we're + # handling this. if issubclass(exc_type, exceptions.CancelledError): - # Since there are no new cancel requests, we're - # handling this. raise TimeoutError from exc_val + elif exc_val is not None: + self._insert_timeout_error(exc_val) + if isinstance(exc_val, ExceptionGroup): + for exc in exc_val.exceptions: + self._insert_timeout_error(exc) elif self._state is _State.ENTERED: self._state = _State.EXITED @@ -126,6 +131,16 @@ class Timeout: # drop the reference early self._timeout_handler = None + @staticmethod + def _insert_timeout_error(exc_val: BaseException) -> None: + while exc_val.__context__ is not None: + if isinstance(exc_val.__context__, exceptions.CancelledError): + te = TimeoutError() + te.__context__ = te.__cause__ = exc_val.__context__ + exc_val.__context__ = te + break + exc_val = exc_val.__context__ + def timeout(delay: Optional[float]) -> Timeout: """Timeout async context manager. |