Events¶
For a guide and examples see Hive events.
- subscribe(callback, eventTypes=None, weak=True)¶
Subscribes to Hive events(rig/component create, delete, rename, build and configuration changes) for every rig. Delivery is synchronous, listener exceptions are logged and never reach Hive.
- Parameters:
- Returns:
The callback.
- Return type:
callable
- unsubscribe(callback)¶
Removes every subscription made with the callback.
- Parameters:
callback (callable) – The callable passed to
subscribe().- Returns:
True if a subscription was removed.
- Return type:
Event system for Hive.
A single EventDispatcher instance lives on zoo.libs.hive.base.configuration.Configuration
as a class variable, so every rig shares it and a tool only needs to subscribe once.
This module deliberately has no Maya imports so it can be unit tested headless.
Delivery is synchronous, on the emitting thread. Listener exceptions are logged and swallowed so a broken listener can never abort or corrupt a Hive operation.
Every started delete has exactly one terminal event, *_DELETED or *_DELETE_FAILED.
from zoo.libs.hive import api
def onEvent(event):
if event.eventType == api.HiveEventType.RIG_RENAMED:
print(event.oldValue, event.newValue)
api.subscribe(onEvent)
api.subscribe(onEvent, eventTypes=(api.HiveEventType.RIG_DELETING,))
api.unsubscribe(onEvent)
- MAX_EMIT_DEPTH: int = 8¶
Nested emits (a listener that triggers another event) deeper than this are dropped.
- SLOW_LISTENER_SECONDS: float = 0.05¶
Listeners slower than this (seconds) are reported at debug level.
- class HiveEventType(*values)¶
Bases:
IntEnumEnumeration of the events emitted by Hive.
An
IntEnumso the members still compare and hash as plain ints.- RIG_CREATED = 0¶
A new rig was created in the scene.
- RIG_DELETING = 1¶
Before a rig delete starts. Nothing has been touched yet,
event.rigis fully valid.
- RIG_DELETED = 2¶
A rig was deleted.
event.rigis None, useevent.rigName.
- RIG_DELETE_FAILED = 3¶
A rig delete raised after
RIG_DELETING. The rig may be partially deleted.
- RIG_RENAMED = 4¶
A rig was renamed.
oldValue/newValueare the names.
- COMPONENT_ADDED = 5¶
A component was added to a rig.
- COMPONENT_DELETING = 6¶
Before a component delete starts.
event.componentis fully valid.
- COMPONENT_DELETED = 7¶
A component was deleted. Use
event.componentToken.
- COMPONENT_DELETE_FAILED = 8¶
A component delete raised after
COMPONENT_DELETING. The component may be partially deleted.
- COMPONENT_RENAMED = 9¶
side” tokens.
- Type:
A component was renamed or its side changed.
oldValue/newValueare the “name
- BUILD_STATE_CHANGED = 10¶
A build/delete stage finished successfully.
event.stageis aconstants.*_FUNC_TYPE.
- BUILD_FAILED = 11¶
A build/delete stage failed or was cancelled, see
error,traceback,cancelled.
- CONFIGURATION_CHANGED = 12¶
A configuration value changed.
key,oldValue,newValue.keyNone means “unspecified”.
- REGISTRIES_RELOADED = 13¶
The configuration registries (components, templates, build scripts…) were reloaded.
- IMMEDIATE_EVENTS: FrozenSet[HiveEventType] = frozenset({HiveEventType.RIG_DELETING, HiveEventType.RIG_DELETE_FAILED, HiveEventType.COMPONENT_DELETING, HiveEventType.COMPONENT_DELETE_FAILED, HiveEventType.BUILD_FAILED})¶
Events that must reach listeners immediately, even inside
EventDispatcher.blocked(). A pre-delete event is useless once the nodes are gone, and failures must not be reordered or dropped.
- class HiveEvent(eventType, rig=None, rigName='', component=None, componentToken=None, key=None, oldValue=None, newValue=None, stage=None, error=None, traceback=None, cancelled=False, buildContext=None)¶
Bases:
objectData object passed to every listener.
Frozen so a listener can’t alter what the listeners after it see.
eq=Falsekeeps identity comparison, the rig and component are live objects which shouldn’t be compared by value.Note
rigandcomponentwrap Maya nodes, don’t keep them beyond the callback.- Parameters:
eventType (HiveEventType) – One of the
HiveEventTypeconstants.rig (Optional[hiverig.Rig]) – The rig the event relates to, None for
RIG_DELETEDor events without a rig.rigName (str) – The rig name.
component (Optional[hivecomponent.Component]) – The component the event relates to, if any.
componentToken (Optional[str]) –
"name:side"of the component, still valid after a delete.key (Optional[str]) – Configuration key for
CONFIGURATION_CHANGED.oldValue (Any) – The previous value, for rename/config events.
newValue (Any) – The new value, for rename/config events.
stage (Optional[int]) – One of the
constants.*_FUNC_TYPEfor build events.error (Optional[BaseException]) – The exception for failure events.
traceback (Optional[str]) – The formatted traceback for failure events.
cancelled (bool) – True for
BUILD_FAILEDevents caused by a user cancel.buildContext (Optional[hivebuildcontext.BuildContext]) – The build context of the failing build.
- eventType: HiveEventType¶
- oldValue: Any = None¶
- newValue: Any = None¶
- error: BaseException | None = None¶
- class EventDispatcher¶
Bases:
objectThread safe, exception isolating, synchronous event dispatcher.
- subscribe(callback, eventTypes=None, weak=True)¶
Registers a callable to be invoked with a
HiveEvent.Subscribing the same callback with the same
eventTypestwice is a no-op.- Parameters:
callback (Callable[[HiveEvent], None]) – A callable accepting a single
HiveEvent.eventTypes (Iterable[int] | None) –
HiveEventTypeconstants to receive, None for all events.weak (bool) – If True(default) bound methods are weakly referenced, so the subscription dies with its owner. Plain functions and lambdas are always held strongly.
- Returns:
The callback, so this can be used as a decorator.
- Return type:
- unsubscribe(callback)¶
Removes every subscription of the callback. Unknown callbacks are ignored.
- Parameters:
callback (Callable[[HiveEvent], None]) – The callable passed to
subscribe().- Returns:
True if at least one subscription was removed.
- Return type:
- clear()¶
Removes all subscriptions.
- listenerCount()¶
Returns the number of live subscriptions.
- blocked()¶
Holds back success events on the current thread until the block exits, then delivers them, de-duplicating repeated build/configuration events. Events in
IMMEDIATE_EVENTSare never held.The held events are delivered even when the body raises. Blocks nest, only the outermost delivers.