Skip to content

ModelEventBus

ModelEventBus

ModelEventBus()

Per-model publish/subscribe bus owned by a Model.

A Model creates one ModelEventBus and exposes it through model.events. Managers and advanced components use that bus to coordinate lifecycle work without tightly coupling themselves to one another.

Callbacks are registered per FemoraEvent and are invoked with keyword-argument payload data supplied by the emitter.

Example
from femora.core.model import Model
from femora.components.event.event_bus import FemoraEvent

model = Model()

def on_post_assemble(**payload):
    assembled_mesh = payload.get("assembled_mesh")
    if assembled_mesh is not None:
        print(assembled_mesh.n_points)

model.events.subscribe(FemoraEvent.POST_ASSEMBLE, on_post_assemble)

Initialize an empty per-model subscriber registry.

Methods:

Name Description
subscribe

Register a callback for one lifecycle event.

unsubscribe

Remove a previously registered callback from one event.

clear

Remove all subscribers, including model-internal lifecycle handlers.

Methods:

subscribe

subscribe(event: FemoraEvent, callback: Callable) -> None

Register a callback for one lifecycle event.

If the callback is already subscribed to the same event, it is not added a second time.

Parameters:

Name Type Description Default
event FemoraEvent

Lifecycle event to listen for.

required
callback Callable

Callable invoked when event is emitted. The callback receives keyword arguments from the emitter.

required

Callbacks execute synchronously in subscription order and are retained strongly. Exceptions propagate to the emitter, potentially interrupting assembly/export. Use flexible keyword payload handling when appropriate.

unsubscribe

unsubscribe(event: FemoraEvent, callback: Callable) -> None

Remove a previously registered callback from one event.

Parameters:

Name Type Description Default
event FemoraEvent

Lifecycle event previously used during subscription.

required
callback Callable

Callback to remove.

required

clear

clear() -> None

Remove all subscribers, including model-internal lifecycle handlers.

Prefer unsubscribing a particular user callback instead of clearing an active model's bus. Model.clear_model re-establishes its built-in hooks as part of coordinated clearing; this method alone does not do that.