Repository navigation
Commit cb3bc41
fix: keep event order, measure delays on the monotonic clock, cancel by marking (#665)
Three fixes to how the engines order, time and cancel events, and a
refactor that removes every suppression from the modules they touch.
Events due at the same moment kept their order only by chance: both
queues are PriorityQueues ordered by execution_time alone, so triggers
stamped alike came out in heap order. TriggerData now numbers each
trigger as it is created and compares that number after execution_time.
Delays were measured on the wall clock, so a step of time.time() held
or hastened every due time. Stamps and due checks now use
time.monotonic().
Cancelling a delayed event filtered the list behind the heap, which is
not always a heap afterwards, and dropped the trigger's future, so a
coroutine awaiting it on the async engine was never answered.
cancel_event() now marks each trigger sent with the send_id as
cancelled and answers its future with None; the queue drops cancelled
triggers from its head. EventQueue.pop_due() pops the head only once it
is due, under the queue's mutex, so a trigger waiting on its delay never
leaves the queue and a cancel from another thread always finds it.
No type: ignore, noqa, pragma: no cover or pragma: no branch is left in
engines/base.py, engines/sync.py, engines/async_.py or statemachine.py.
The methods only the sync engine implements synchronously moved from
BaseEngine to SyncEngine, each processing loop is split into its
macrostep, the external events and one external event, and the code
the pragmas hid is either removed as unreachable or covered by a test.
Release notes in docs/releases/3.2.2.md.
Co-authored-by: Fernando Macedo <fgmacedo@gmail.com>
Signed-off-by: Fernando Macedo <fgmacedo@gmail.com>1 parent fe5f070 commit cb3bc41
13 files changed
Lines changed: 1222 additions & 493 deletions
File tree
- docs
- releases
- statemachine
- engines
- tests
- scxml
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
79 | 116 | | |
80 | 117 | | |
81 | 118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| 116 | + | |
| 117 | + | |
116 | 118 | | |
117 | 119 | | |
118 | 120 | | |
| |||
Large diffs are not rendered by default.
0 commit comments