subscribe(self, 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.
- callback : callable
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_type : str, 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
- run : bool, optional
Run the callback now
- cid : int
id of callback, can be passed to unsubscribe to remove the callback