Print parameter value each time it changes / identifying which parameter changed in @depends

Hi all,

for debugging purposes I’d like to get an exact chronology of which parameters is set with what value. Does param already have this capability? I know I could set some hook with @depends(..., watch=True) on every single parameter, but that’s tedious if I have to do it for every single parameter.

Is there maybe a way using depends that allows me to figure out which parameter it was that triggered the change, so I can pull that one out manually?

Thanks in advance!

Again, the docs have become really good since last time I checked, kudos to the dev team!

Here is a worked example very similar to what I want to do:
https://param.holoviz.org/user_guide/Dependencies_and_Watchers.html#watchers

def e(e):
    return f"(event: {e.name} changed from {e.old} to {e.new})"

class P(param.Parameterized):
    a = param.Integer(default=0)
    b = param.Integer(default=0)
    
    def __init__(self, **params):
        super().__init__(**params)
        self.param.watch(self.run_a1, ['a'], queued=True, precedence=2)
        self.param.watch(self.run_a2, ['a'], precedence=1)
        self.param.watch(self.run_b,  ['b'])

    def run_a1(self, event):
        self.b += 1
        print('a1', self.a, e(event))

    def run_a2(self, event):
        print('a2', self.a, e(event))

    def run_b(self, event):
        print('b', self.b, e(event))
        
p = P()

p.a = 1
1 Like