Module

_state

Server lifecycle state machine — Elm Architecture via milo.

Centralizes the server lifecycle (init → startup → ready → serving → reloading → shutting_down → stopped) into an immutable state model with a pure reducer. A render middleware produces branded output on each dispatch, replacing the proceduralif _is_pretty(): _write(_render(...))pattern with a single dispatch-driven view layer.

Usage from server.py / supervisor.py::

from pounce._state import dispatch

dispatch("BANNER", config=config, effective_workers=4, ...)
dispatch("READY", host="127.0.0.1", port=8000)
dispatch("SHUTDOWN_COMPLETE")

Classes

Phase 0
Server lifecycle phases.

Server lifecycle phases.

ServerModel 7
Immutable server lifecycle state.

Immutable server lifecycle state.

Attributes

Name Type Description
phase Phase
effective_workers int
mode_label str
gil_status str
supervisor_mode str
generation int
connections int

Functions

server_reducer 2 ServerModel
Pure reducer — advances lifecycle state in response to actions.
def server_reducer(state: ServerModel | None, action: Action) -> ServerModel
Parameters
Name Type Description
state ServerModel | None
action Action
Returns
ServerModel
_render_middleware 2
Middleware that renders branded lifecycle output on each action.
def _render_middleware(dispatch_fn, get_state)
Parameters
Name Type Description
dispatch_fn
get_state
_startup_hints 2 list[str]
Generate smart startup hints based on config vs environment.
def _startup_hints(config, effective_workers: int) -> list[str]
Parameters
Name Type Description
config
effective_workers int
Returns
list[str]
_render_action 1 None
Route an action to its branded template or logger fallback.
def _render_action(action: Action) -> None
Parameters
Name Type Description
action Action
_get_store 0 Store
Get or create the lifecycle store (thread-safe, lazy).
def _get_store() -> Store
Returns
Store
dispatch 2 None
Dispatch a lifecycle action to the server store. Example:: dispatch("READ…
def dispatch(action_type: str, **payload: Any) -> None

Dispatch a lifecycle action to the server store.

Example::

dispatch("READY", host="127.0.0.1", port=8000)
dispatch("SHUTDOWN_COMPLETE")
Parameters
Name Type Description
action_type str
**payload Any
get_state 0 ServerModel
Return the current server lifecycle state.
def get_state() -> ServerModel
Returns
ServerModel
_reset_store 0 None
Reset the store to initial state (testing only).
def _reset_store() -> None