gh-110733: Micro-optimization in BaseEventLoop._run_once (#110735)

This commit is contained in:
J. Nick Koston 2023-10-11 10:59:27 -10:00 committed by GitHub
parent 41d8ec5a1b
commit 3ac8e6955f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View file

@ -1907,8 +1907,11 @@ class BaseEventLoop(events.AbstractEventLoop):
timeout = 0
elif self._scheduled:
# Compute the desired timeout.
when = self._scheduled[0]._when
timeout = min(max(0, when - self.time()), MAXIMUM_SELECT_TIMEOUT)
timeout = self._scheduled[0]._when - self.time()
if timeout > MAXIMUM_SELECT_TIMEOUT:
timeout = MAXIMUM_SELECT_TIMEOUT
elif timeout < 0:
timeout = 0
event_list = self._selector.select(timeout)
self._process_events(event_list)