- OphydObject.subscribe(callback, event_type=None, run=True)¶
Subscribe to events this event_type generates.
The callback will be called as
cb(*args, **kwargs)with the values passed to _run_subs with the following additional keys:
sub_type : the string value of the event_type obj : the host object, added if ‘obj’ not already in kwargs
if the key ‘timestamp’ is in kwargs _and_ is None, then it will be replaced with the current time before running the callback.
**kwargspassed to _run_subs will be cached as shallow copies, be aware of passing in mutable data.
If the callback raises any exceptions when run they will be silently ignored.
A callable function (that takes kwargs) to be run when the event is generated. The expected signature is
def cb(*args, obj: OphydObject, sub_type: str, **kwargs) -> None:
The exact args/kwargs passed are whatever are passed to
- event_typestr, optional
The name of the event to subscribe to (if None, defaults to the default sub for the instance - obj._default_sub)
This maps to the
sub_typekwargs in _run_subs
- runbool, optional
Run the callback now
id of callback, can be passed to unsubscribe to remove the callback