ophyd.ophydobj.OphydObject.subscribe#

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.

The *args, **kwargs passed to _run_subs will be cached as shallow copies, be aware of passing in mutable data.

Warning

If the callback raises any exceptions when run they will be silently ignored.

Parameters:
callbackcallable

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 _run_subs

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_type kwargs in _run_subs

runbool, optional

Run the callback now

Returns:
cidint

id of callback, can be passed to unsubscribe to remove the callback

See also

clear_sub, _run_subs