gh-95051: ensure that timeouts scheduled with asyncio.Timeout that have already expired are deliverered promptly (GH-95109) (GH-95216)

Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
(cherry picked from commit 0c6f898005)

Co-authored-by: Thomas Grainger <tagrain@gmail.com>
This commit is contained in:
Miss Islington (bot) 2022-07-26 03:16:12 -07:00 committed by GitHub
parent 2fb64a0687
commit 19d953682e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 4 deletions

View file

@ -52,10 +52,10 @@ class Timeout:
self._timeout_handler = None
else:
loop = events.get_running_loop()
self._timeout_handler = loop.call_at(
when,
self._on_timeout,
)
if when <= loop.time():
self._timeout_handler = loop.call_soon(self._on_timeout)
else:
self._timeout_handler = loop.call_at(when, self._on_timeout)
def expired(self) -> bool:
"""Is timeout expired during execution?"""