A deterministic three-state stop controller.
Stop conditions in most systems are afterthoughts — flags checked late, states that can be bypassed, or halts that leave the system in an undefined state. This primitive makes stopping a first-class structural guarantee: three states, one direction, no reversal. Once the machine reaches RED, it stays there. No configuration can override it, no runtime condition can reset it. If your system needs a provably terminal stop, this is the brick.
GREEN -> AMBER -> RED (terminal)
RED is terminal. No implicit transitions. No global state.
from stop_machine import StopMachine, State
m = StopMachine() # starts GREEN
m.advance() # -> AMBER
m.advance() # -> RED (terminal)
m.advance() # raises TerminalStateErrorm = StopMachine()
m.transition_to(State.AMBER) # ok
m.transition_to(State.GREEN) # raises InvalidTransitionErrorm = StopMachine(State.RED)
m.reset() # -> GREENpip install pytest
pytest test_stop_machine.py -v- Deterministic behaviour only
- No global state
- <200 LOC implementation
- All transitions explicit
- RED is terminal
MIT