betty.life_cycle.manage module#

Life cycle management.

final class betty.life_cycle.manage.LifeCycleManager#

Bases: LifeCycle

A life cycle manager.

__init__()#
async bootstrap() None#

Bootstrap the object.

on(*callbacks: tuple[Bootstrapper, Shutdowner]) None#

Add a batch of callbacks.

The callbacks within the batch will be invoked concurrently.

on_bootstrap(*bootstrappers: Bootstrapper) None#

Add a batch of bootstrap callbacks.

The callbacks within the batch will be invoked concurrently.

on_shutdown(*shutdowners: Shutdowner) None#

Add a batch of shutdown callbacks.

The callbacks within the batch will be invoked concurrently.

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

Shut the object down.

async synchronize(*life_cycles: Bootstrappable | Shutdownable) None#

Attach a batch of other life cycles to this one, and ensure they are all synchronized.

The life cycles within the batch will be bootstrapped and shut down concurrently.

class betty.life_cycle.manage.ManagedLifeCycle#

Bases: LifeCycle

An object that can bootstrap and shut down, and manage resources upon these events.

Subclasses and third party code can manage resources using the life_cycle property, which ensures everything is done in order.

__init__(*args: Any, **kwargs: Any)#
final async bootstrap() None#

Bootstrap the object.

life_cycle: Final[LifeCycleManager]#

The life cycle manager.

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

Shut the object down.