Allow overriding Timer's drift-warning threshold#78
Open
wbarnha wants to merge 1 commit into
Open
Conversation
Timer.max_drift was always auto-computed as min(interval_s * 0.30, 1.2s), with no way for a caller to configure it. For ServiceThread's internal 1s keepalive timer specifically, this meant any app with slightly bursty scheduling would get "Timer ... woke up too late" log spam at the default INFO level with no way to raise the threshold short of monkeypatching mode.timers module constants. Add an optional `max_drift` parameter to Timer.__init__, defaulting to None (preserves the existing auto-computed heuristic exactly). Thread it through Service.itertimer() so any timer a Service starts can override it. Add a `keepalive_max_drift` class attribute to ServiceThread (default None, same auto-computed behavior) that flows into the internal keepalive timer specifically, since that's the timer the issue is actually about -- subclasses or instances can now set it directly instead of needing to touch module globals. Tests cover: the default heuristic is unchanged when max_drift is omitted; an explicit higher max_drift suppresses a drift that would otherwise warn (both early and late); an explicit lower max_drift makes a normally-silent drift warn (proving the override works in both directions, not just as a one-way "quiet down" escape hatch); and ServiceThread.keepalive_max_drift is correctly forwarded to itertimer. Assisted-by: Claude Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HgnKFtXZbCjXNoVNWa5JLd
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.
Description
Fixes #46.
Timer.max_driftwas always auto-computed asmin(interval_s * 0.30, 1.2s), with no way for a caller to configure it. ForServiceThread's internal 1s keepalive timer specifically, this meant any app with slightly bursty scheduling would getTimer ... woke up too latelog spam at the default INFO level with no way to raise the threshold short of monkeypatchingmode.timersmodule constants — exactly the issue's complaint.Changes
Timer.__init__gains an optionalmax_driftparameter, defaulting toNone(preserves the existing auto-computed heuristic exactly, no behavior change for existing callers).Service.itertimer()threadsmax_driftthrough so any timer aServicestarts can override it.ServiceThreadgains akeepalive_max_driftclass attribute (defaultNone, same auto-computed behavior) that flows into the internal_thread_keepalivetimer specifically — subclasses or instances can now set it directly instead of touching module globals.Verification
max_driftis omitted; an explicit highermax_driftsuppresses a drift that would otherwise warn (both early and late); an explicit lowermax_driftmakes a normally-silent drift warn, proving the override works in both directions, not just as a one-way "quiet down" escape hatch; andServiceThread.keepalive_max_driftis correctly forwarded toitertimer.🤖 Generated with Claude Code
https://claude.ai/code/session_01HgnKFtXZbCjXNoVNWa5JLd
Generated by Claude Code