This repository has been archived by the owner on Sep 14, 2020. It is now read-only.
Distinguish "no handlers at all" and "no handers for now" cases #285
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.
What do these changes do?
Fixes an issue with time discrepancies that stopped the reaction cycle if the operator was unlucky enough to hit the scheduled awakening time with 1ms precision.
Description
Previously, "now" of
handler.awakened
and "now" ofstate.delay
were different (maybe for less than 1 ms). If the scheduled awakening time was unlucky to be between these two points in time, the operator stopped reacting on this object until any other events or changes arrive.Specifically, the operator neither selected the handlers to be executed (because it was "1ms too early" for the
handler.awakened
), nor did it sleep (because it was "1ms too late" in thestate.delay
property) — with the same value ofdelayed
field, just the code being executed exactly during this awakening time.Due to how zero-time delay is treated (i.e. same as
None
— no sleep at all), the dummy patch was not applied to trigger the next steps of the reaction cycle.After the fix,
0
-delay andNone
-delay are treated differently: the zero-time delay does not sleep, but produces a dummy patch to trigger the reaction cycle after the sleep is over (as if it was an actual zero-time sleep). TheNone
delay does not do any sleeping or dummy patching.This eliminates the problem with the "now" time inconsistencies, while keeps the multiple
datetime.datetime.utcnow()
possible — to properly calculate the needed sleep time without the code overhead included.The change does not affect the users directly. The probability of hitting this issue was low anyway.
Issues/PRs
Type of changes
Checklist
CONTRIBUTORS.txt