class documentation

class LifecycleMixin:

View In Hierarchy

Mixin managing the lifecycle of classes with @resource decorated methods.

Method __init_subclass__ Determine the initialization order for a specific subclass.
Async Method init Idempotent. Initialize all resources in dependency order.
Async Method shutdown Idempotent. Run each resource's post-yield code in reverse dependency order.
Property is_initialized Return True if initialized, False otherwise.
Property lifecycle_order Return resolved init order (shutdown runs in reverse).
Property lifecycle_state Return the lifecycle state.
Async Method __close_one Undocumented
Async Method __shutdown Shut down in reverse order, best-effort. Returns all caught exceptions.
Class Variable __order Undocumented
Instance Variable __generators Undocumented
Instance Variable __state Undocumented
def __init_subclass__(cls, **kwargs):

Determine the initialization order for a specific subclass.

Raises
CycleErrorIf there is a cycle in the dependency graph.
async def init(self) -> Self:

Idempotent. Initialize all resources in dependency order.

On failure, rollback anything already started, in reverse.

Raises
BaseExceptionReraised exception from failed resource initialization.
ExceptionGroupIf exceptions were caught during rollback.
async def shutdown(self):

Idempotent. Run each resource's post-yield code in reverse dependency order.

@property
is_initialized: bool =

Return True if initialized, False otherwise.

@property
lifecycle_order: list[_Func] =

Return resolved init order (shutdown runs in reverse).

@property
lifecycle_state: LifecycleState =

Return the lifecycle state.

async def __close_one(self, func: _Func):

Undocumented

async def __shutdown(self, funcs: list[_Func]) -> list[Exception]:

Shut down in reverse order, best-effort. Returns all caught exceptions.

__order: list[_Func] | None =

Undocumented

__generators: dict[_Func, AsyncGenerator[None, None]] | None =

Undocumented

__state =

Undocumented