betty.life_cycle package

Submodules

Module contents

Life cycle and resource management.

exception betty.life_cycle.AlreadyBootstrapped

Bases: LifeCycleError

Raised if a life cycle was unexpectedly already bootstrapped.

exception betty.life_cycle.AlreadyShutDown

Bases: AlreadyBootstrapped

Raised if a life cycle was unexpectedly already shut down.

class betty.life_cycle.Bootstrappable

Bases: _LifeCycleContextManager

An object that can be bootstrapped.

__init__(*args: Any, **kwargs: Any)
final assert_bootstrapped() None

Assert that the object is bootstrapped.

final assert_not_bootstrapped() None

Assert that the object is not yet bootstrapped.

async bootstrap() None

Bootstrap the object.

property bootstrapped: bool

Whether the object has been bootstrapped.

class betty.life_cycle.LifeCycle

Bases: Bootstrappable, Shutdownable

An object that can be bootstrapped and shut down.

property alive: bool

Whether the object is alive, e.g. bootstrapped but not shut down.

final assert_alive() None

Assert that the object is alive, e.g. bootstrapped but not shut down.

exception betty.life_cycle.LifeCycleError

Bases: RuntimeError

Raised for life cycle related errors.

exception betty.life_cycle.NotYetBootstrapped

Bases: LifeCycleError

Raised if a life cycle was unexpectedly not yet bootstrapped.

class betty.life_cycle.Shutdownable

Bases: _LifeCycleContextManager

An object that can be shut down.

__init__(*args: Any, **kwargs: Any)
final assert_not_shut_down() None

Assert that the object is not yet shut down.

property shut_down: bool

Whether the object has been shut down.

async shutdown(*, wait: bool = True) None

Shut the object down.

class betty.life_cycle.ShutdownerKwargs

Bases: TypedDict

The keyword arguments to a shutdown callback.

wait: bool

True to wait for the component to shut down gracefully, or False to attempt an immediate forced shutdown.