param.parameterized.Parameters.watch_values#

Parameters.watch_values(fn: Callable, parameter_names: str | list[str], what: Literal['value'] = 'value', onlychanged: bool = True, queued: bool = False, precedence: int = 0) Watcher[source]#

Register a callback function for changes in parameter values.

This method is a simplified version of watch(), specifically designed for monitoring changes in parameter values. Unlike watch(), the callback is invoked with keyword arguments (<param_name>=<new_value>) instead of Event objects.

Parameters:
  • fn (Callable) – The callback function to invoke when a parameter value changes. The function is called with keyword arguments where the parameter names are keys, and their new values are values.

  • parameter_names (str or list of str) – The name(s) of the parameters to monitor. Can be a single parameter name, a list of parameter names, or a tuple of parameter names.

  • what (str, optional) –

    The type of change to watch for. Must be 'value'. Default is 'value'.

    Deprecated since version 2.3.0.

  • onlychanged (bool, optional) – If True (default), the callback is only invoked when the parameter value changes. If False, the callback is invoked even when the parameter is set to its current value.

  • queued (bool, optional) – By default (False), additional watcher events generated inside the callback fn are dispatched immediately, effectively doing depth-first processing of Watcher events. However, in certain scenarios, it is helpful to wait to dispatch such downstream events until all events that triggered this watcher have been processed. In such cases setting queued=True on this Watcher will queue up new downstream events generated during fn until fn completes and all other watchers invoked by that same event have finished executing), effectively doing breadth-first processing of Watcher events.

  • precedence (int, optional) – The precedence level of the watcher. Lower precedence values are executed earlier. User-defined watchers must use positive precedence values. Default is 0.

Returns:

The Watcher object encapsulating the registered callback.

Return type:

Watcher

Notes

  • This method is a convenient shorthand for watch() when only monitoring changes in parameter values is needed.

  • Callback functions receive new values as keyword arguments, making it easier to work with parameter updates.

See also

watch

General-purpose watcher registration supporting a broader range of events.

Examples

Monitor parameter value changes:

>>> import param
>>> class MyClass(param.Parameterized):
...     a = param.Number(default=1)
...     b = param.Number(default=2)
...
...     def callback(self, a=None, b=None):
...         print(f"Callback triggered with a={a}, b={b}")
...
>>> instance = MyClass()

Register a watcher:

>>> instance.param.watch_values(instance.callback, ['a', 'b'])
Watcher(inst=MyClass(a=1, b=2, name=...)

Trigger changes to invoke the callback:

>>> instance.a = 10
Callback triggered with a=10, b=None
>>> instance.b = 20
Callback triggered with a=None, b=20