param.discard_events#

param.discard_events(parameterized: Parameterized) Generator[None, None, None][source]#

Context manager that discards any events within its scope triggered on the supplied Parameterized object.

The discard_events context manager ensures that any events triggered on the supplied Parameterized object during its scope are discarded. This allows for silent changes to dependent parameters, making it useful for initialization or setup phases where changes should not propagate to watchers or dependencies.

Be cautious when using this context manager, as it bypasses the normal dependency mechanism. Manual changes made within this context may leave the object in an inconsistent state if dependencies are meant to ensure parameter consistency.

Parameters:

parameterized (Parameterized) – The Parameterized object whose events will be suppressed.

Yields:

None – A context where events on the supplied Parameterized object are discarded.

References

For more details, see the Param User Guide: https://param.holoviz.org/user_guide/Dependencies_and_Watchers.html#discard-events

Examples

Instantiate Parameterized and print its value(s) when changed:

>>> import param
>>> class MyClass(param.Parameterized):
...     a = param.Number(default=1)
...
...     @param.depends('a', watch=True)
...     def on_a(self):
...         print(self.a)
>>> p = MyClass()
>>> p.a = 2
2

Use discard_events to suppress events:

>>> with param.parameterized.discard_events(p):
...     p.a = 3
# Nothing is printed