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:
  • callback (callable) – A callable accepting a single HiveEvent.

  • eventTypes (collections.Iterable[int] or None) – HiveEventType constants to receive, None for all events.

  • weak (bool) – If True bound methods are weakly referenced, the subscription dies with its owner.

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:

bool

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: IntEnum

Enumeration of the events emitted by Hive.

An IntEnum so 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.rig is fully valid.

RIG_DELETED = 2

A rig was deleted. event.rig is None, use event.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/newValue are the names.

COMPONENT_ADDED = 5

A component was added to a rig.

COMPONENT_DELETING = 6

Before a component delete starts. event.component is 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/newValue are the “name

BUILD_STATE_CHANGED = 10

A build/delete stage finished successfully. event.stage is a constants.*_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. key None 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.

Listener

A callable which receives a single HiveEvent.

alias of Callable[[HiveEvent], None]

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: object

Data object passed to every listener.

Frozen so a listener can’t alter what the listeners after it see. eq=False keeps identity comparison, the rig and component are live objects which shouldn’t be compared by value.

Note

rig and component wrap Maya nodes, don’t keep them beyond the callback.

Parameters:
  • eventType (HiveEventType) – One of the HiveEventType constants.

  • rig (Optional[hiverig.Rig]) – The rig the event relates to, None for RIG_DELETED or 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_TYPE for build events.

  • error (Optional[BaseException]) – The exception for failure events.

  • traceback (Optional[str]) – The formatted traceback for failure events.

  • cancelled (bool) – True for BUILD_FAILED events caused by a user cancel.

  • buildContext (Optional[hivebuildcontext.BuildContext]) – The build context of the failing build.

eventType: HiveEventType
rig: hiverig.Rig | None = None
rigName: str = ''
component: hivecomponent.Component | None = None
componentToken: str | None = None
key: str | None = None
oldValue: Any = None
newValue: Any = None
stage: int | None = None
error: BaseException | None = None
traceback: str | None = None
cancelled: bool = False
buildContext: hivebuildcontext.BuildContext | None = None
class EventDispatcher

Bases: object

Thread 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 eventTypes twice is a no-op.

Parameters:
  • callback (Callable[[HiveEvent], None]) – A callable accepting a single HiveEvent.

  • eventTypes (Iterable[int] | None) – HiveEventType constants 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:

Callable[[HiveEvent], None]

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:

bool

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_EVENTS are never held.

The held events are delivered even when the body raises. Blocks nest, only the outermost delivers.

emit(event)

Delivers the event to all matching listeners. Never raises.

Parameters:

event (HiveEvent) – The event to deliver.