cayu.runtime.application_lifecycle
Public Cayu API. Definitions are grouped by their public source module, and definitions from private implementation modules appear on their package’s page; adding a symbol does not move existing links. The import shown at each entry is a supported public namespace. Read the Python API overview and install the required extra.
ApplicationAdmission
Section titled “ApplicationAdmission”from cayu import ApplicationAdmissionSeal-once gate for local entrances, counting operations still in flight.
Each operation counts once: a call it makes in its own task is part of it. Work an admitted operation starts while still running, including in a background task that outlives it, is not refused after sealing, and that task is counted so shutdown waits for it. Once the operation finished, its leftover tasks are refused like any other new work.
init (method)
Section titled “init (method)”ApplicationAdmission.__init__() -> Nonesealed (property)
Section titled “sealed (property)”ApplicationAdmission.sealed() -> boolin_flight (property)
Section titled “in_flight (property)”ApplicationAdmission.in_flight() -> intclosed (property)
Section titled “closed (property)”ApplicationAdmission.closed() -> boolseal (method)
Section titled “seal (method)”ApplicationAdmission.seal() -> NoneRefuse new top-level operations; idempotent and never reopened.
close (method)
Section titled “close (method)”ApplicationAdmission.close() -> NoneRefuse every operation from now on, including tracked ones.
The final transition before releasing what operations depend on: unlike
seal, nothing is admitted or tracked afterwards.
acquire (method)
Section titled “acquire (method)”ApplicationAdmission.acquire() -> _AdmissionLeaseAdmit and count one operation, unless sealed and not started by admitted work.
track (method)
Section titled “track (method)”ApplicationAdmission.track() -> _AdmissionLeaseCount one operation that stays allowed while the application drains.
release (method)
Section titled “release (method)”ApplicationAdmission.release(lease: _AdmissionLease) -> Nonewait_idle (method)
Section titled “wait_idle (method)”async ApplicationAdmission.wait_idle(timeout_s: float) -> boolWait until no admitted operation remains, up to timeout_s.
Release source · Runtime guarantees · Capability guides
ApplicationAdmissionsSealed
Section titled “ApplicationAdmissionsSealed”from cayu import ApplicationAdmissionsSealedA new local operation cannot start after the application began shutting down.
Bases: RuntimeError.
This type’s implementation and inherited behavior are available in the linked release source.
Release source · Runtime guarantees · Capability guides
ApplicationShutdown
Section titled “ApplicationShutdown”from cayu import ApplicationShutdownRun ordered shutdown stages under one deadline and report the outcome.
Repeated and concurrent calls share one attempt at a time. A settled outcome is final; after an incomplete or failed outcome, a later call runs a new attempt that first rejoins steps still running from the previous one. A caller’s cancellation propagates to that caller promptly while the attempt finishes within its own deadline.
init (method)
Section titled “init (method)”ApplicationShutdown.__init__(*, admission: ApplicationAdmission, stages: Callable[[], Sequence[ShutdownStage]], late_work: Callable[[], Mapping[str, ApplicationShutdownStepReason]]=dict, owned_resources: Iterable[SupportsAsyncClose]=()) -> Nonestate (property)
Section titled “state (property)”ApplicationShutdown.state() -> ApplicationLifecycleStateaclose (method)
Section titled “aclose (method)”async ApplicationShutdown.aclose(*, timeout_s: float) -> ApplicationShutdownOutcomeRelease source · Runtime guarantees · Capability guides
ApplicationShutdownOutcome
Section titled “ApplicationShutdownOutcome”from cayu import ApplicationShutdownOutcomeTruthful, process-local result of one application shutdown attempt.
settled means every step completed and no owned work remained. It says
nothing about other processes sharing the same durable stores.
Bases: BaseModel.
Fields and attributes
Section titled “Fields and attributes”Defaults below are source expressions; Field(...) includes schema/validation settings and default_factory creates a fresh value. Inherited declarations are included. Constructor behavior follows the model or dataclass shown in the bases/decorators.
| Name | Type | Default |
|---|---|---|
status |
ApplicationShutdownStatus |
required |
attempt |
StrictInt |
Field(ge=1) |
timeout_seconds |
float |
Field(gt=0) |
elapsed_seconds |
float |
Field(ge=0) |
steps |
tuple[ApplicationShutdownStep, ...] |
required |
open_operations |
StrictInt |
Field(ge=0) |
owned_resources |
OwnedResourcesStatus |
required |
scope |
Literal['process_local'] |
'process_local' |
settled (property)
Section titled “settled (property)”ApplicationShutdownOutcome.settled() -> boolstep (method)
Section titled “step (method)”ApplicationShutdownOutcome.step(subsystem: str) -> ApplicationShutdownStep | Noneunsettled (property)
Section titled “unsettled (property)”ApplicationShutdownOutcome.unsettled() -> tuple[ApplicationShutdownStep, ...]summary (method)
Section titled “summary (method)”ApplicationShutdownOutcome.summary() -> strOne content-free line describing this attempt, for logs and terminals.
Release source · Runtime guarantees · Capability guides
ApplicationShutdownStep
Section titled “ApplicationShutdownStep”from cayu import ApplicationShutdownStepContent-free outcome of one shutdown step.
Bases: BaseModel.
Fields and attributes
Section titled “Fields and attributes”Defaults below are source expressions; Field(...) includes schema/validation settings and default_factory creates a fresh value. Inherited declarations are included. Constructor behavior follows the model or dataclass shown in the bases/decorators.
| Name | Type | Default |
|---|---|---|
subsystem |
StrictStr |
required |
status |
ApplicationShutdownStepStatus |
required |
budget_seconds |
float |
Field(ge=0) |
elapsed_seconds |
float |
Field(ge=0) |
reason |
ApplicationShutdownStepReason | None |
None |
failure_type |
StrictStr | None |
None |
Release source · Runtime guarantees · Capability guides
ShutdownBudget
Section titled “ShutdownBudget”from cayu import ShutdownBudgetOne deadline shared by a sequence of bounded shutdown operations.
init (method)
Section titled “init (method)”ShutdownBudget.__init__(timeout_s: float) -> Noneremaining (method)
Section titled “remaining (method)”ShutdownBudget.remaining() -> floatSeconds left before the shared deadline, never negative.
expired (method)
Section titled “expired (method)”ShutdownBudget.expired() -> boolelapsed (method)
Section titled “elapsed (method)”ShutdownBudget.elapsed() -> floatstep_budget (method)
Section titled “step_budget (method)”ShutdownBudget.step_budget(*, floor_s: float=0.0) -> floatThe remaining time, or floor_s when that is larger.
Release source · Runtime guarantees · Capability guides
ShutdownStepSpec
Section titled “ShutdownStepSpec”from cayu import ShutdownStepSpecOne bounded shutdown operation.
run receives its time budget and returns True/None when settled or False
when work remains. floor_protected steps still run after the shared
deadline is exhausted because their timeout path performs local cleanup.
seal synchronously refuses the subsystem’s new work; it runs even when
the deadline is exhausted and the drain itself is skipped.
Decorators: @dataclass(frozen=True).
Fields and attributes
Section titled “Fields and attributes”Defaults below are source expressions; Field(...) includes schema/validation settings and default_factory creates a fresh value. Inherited declarations are included. Constructor behavior follows the model or dataclass shown in the bases/decorators.
| Name | Type | Default |
|---|---|---|
subsystem |
str |
required |
run |
Callable[[float], Awaitable[bool | None]] |
required |
floor_protected |
bool |
False |
incomplete_reason |
ApplicationShutdownStepReason |
'still_draining' |
seal |
Callable[[], None] | None |
None |
Release source · Runtime guarantees · Capability guides
SupportsAsyncClose
Section titled “SupportsAsyncClose”from cayu import SupportsAsyncCloseA resource whose ownership was explicitly transferred to the application.
Bases: Protocol.
close (method)
Section titled “close (method)”async SupportsAsyncClose.close() -> None