Skip to content

Handle zero clock readings in Timer - #90

Open
hakarrr wants to merge 2 commits into
xolox:masterfrom
hakarrr:fix-timer-zero-start
Open

hakarrr wants to merge 2 commits into
xolox:masterfrom
hakarrr:fix-timer-zero-start

Conversation

@hakarrr

@hakarrr hakarrr commented Oct 24, 2026

Copy link
Copy Markdown

Timer(start_time=0) silently selects the automatic monotonic timer instead of measuring from the Unix epoch. A monotonic reading of zero also stops automatic and resumable timers from accumulating elapsed time.

Use None for an inactive resumable timer and check explicitly for None, so zero remains a valid start time. This also keeps a stopped timer from counting time between resumptions.

  • Three deterministic test methods: epoch start (zero, negative and positive controls), zero monotonic start, and paused/resumed lifecycle. Two fail on the unchanged base; the lifecycle control passes.
  • Full suite: 72 passed on each of CPython 3.9, 3.10, 3.11 and 3.12 on Linux.
  • Combined line/branch coverage: 91%; changed Timer branches covered.
  • Changed-file flake8 (including docstrings), diff check, sdist and wheel: pass.

Python 2, earlier Python versions, Windows and macOS were not run. No test or CI configuration changes. Found by reading the timer implementation; no separate reported production incident.

Change start_time from 0.0 to None for better clarity and handling of timer states.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant