Skip to content

Switch to event loop's clock for all timing operations#1206

Merged
nolar merged 4 commits intomainfrom
event-loop-clock
Jan 2, 2026
Merged

Switch to event loop's clock for all timing operations#1206
nolar merged 4 commits intomainfrom
event-loop-clock

Conversation

@nolar
Copy link
Copy Markdown
Owner

@nolar nolar commented Jan 2, 2026

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:

  1. time intervals and timeouts, as used strictly within a single runtime;
  2. timestamps in the persisted states of objects, as shared across several runtimes.

In particular, when it comes to the ISO 8601 timestamps, the ephemeral "base time" is used as a calculated datetime object 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.

Signed-off-by: Sergey Vasilyev <nolar@nolar.info>
@nolar nolar added the refactoring Code cleanup without new features added label Jan 2, 2026
nolar added 3 commits January 2, 2026 15:30
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>
@nolar nolar force-pushed the event-loop-clock branch from ccc42c6 to 017dbe0 Compare January 2, 2026 15:25
@nolar nolar merged commit 2f03e1d into main Jan 2, 2026
39 checks passed
@nolar nolar deleted the event-loop-clock branch January 2, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring Code cleanup without new features added

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants