Switch to event loop's clock for all timing operations#1206
Merged
Conversation
Signed-off-by: Sergey Vasilyev <nolar@nolar.info>
Signed-off-by: Sergey Vasilyev <nolar@nolar.info>
…tervals The routines that depend only on the internal intervals and durations should use the internal loop time only — which can be later faked by e.g. `looptime`. If the system or process time is used, these routines fall out of time-faking and might take many more cycles to reach the desired real-world timestamp (just by letting the real time flow naturally). This does NOT cover the cases with intervals and durations based on the global time (i.e. UTC clock) — e.g. handlers' timeouts, retries, etc. Signed-off-by: Sergey Vasilyev <nolar@nolar.info>
…topped/delayed) Signed-off-by: Sergey Vasilyev <nolar@nolar.info>
ccc42c6 to
017dbe0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a refactoring extracted from the PR with
looptime— a preparation for proper handling of certain time-based situations, separating the wall-clock time from the event-loop time. These changes are unrelated to the refactoring of tests per se, but are directly required to make those work.Specifically, this PR switches all internal use of time from the wall clocks (
time.monotonic(),datetime.datetime.now(), etc) to the event loop's internal clock (loop.time()). This covers both types of time usage:In particular, when it comes to the ISO 8601 timestamps, the ephemeral "base time" is used as a calculated
datetimeobject at when the even loop's time was precisely zero — so that the movement of the event loop's time advances the measurements of the ISO 8601 time as expected, without the wall-clock time actually moving forwards.There are no changes to the behaviour of the operators, it is an internal refactoring only. The code changes are fully backward-compatible.
PS: The changeset is from Nov-Dec'2022, adjusted to the codebase of Jan'2026.