I’m going crazy here I’m obviously missing something, please help me out …
I’m trying to rewrite some automation scripts using callbacks to finally address thread starvation problems
VAR1 = "ABC"
def initialize(self):
self.log("Starting CallbackTesting ...")
self.handle1 = self.run_in(self.CallbackTesting1, test_interval, var1=VAR1)
self.handle2 = self.run_in(self.CallbackTesting2, test_interval+1, var2=VAR1)
self.handle3 = self.run_in(self.CallbackTesting3, test_interval+2)
self.handle4 = self.run_every(self.CallbackTesting4, "now", 5, initial_check=True)
def CallbackTesting1(self, kwargs):
self.log("CallbackTesting1 : " + kwargs["var1"])
def CallbackTesting2(self, kwargs):
self.log("CallbackTesting2 : " + kwargs['var2'])
def CallbackTesting3(self, kwargs):
self.log("CallbackTesting3 : " + VAR1)
def CallbackTesting4(self, kwargs):
self.log("CallbackTesting4 : " + str(kwargs["initial_check"]))
initial_check = kwargs["initial_check"]
if initial_check:
self.cancel_timer(self.handle4)
initial_check = False
self.log("CallbackTesting4 : Setting new run_every schedule")
self.handle4 = self.run_every(self.CallbackTesting4, "now", 7)
def terminate(self):
self.cancel_timer(self.handle1)
self.cancel_timer(self.handle2)
self.cancel_timer(self.handle3)
self.cancel_timer(self.handle4)
The problem lies within def CallbackTesting4(self, kwargs) (and any other def if additional code is added) where if I only have
self.log("CallbackTesting4 : " + str(kwargs["initial_check"]))
it is working normally, the second I add the rest code lines I get
self.log("CallbackTesting4 : " + str(kwargs[“initial_check”]))
~~~~~~^^^^^^^^^^^^^^^^^
KeyError: ‘initial_check’
What am I missing?
PS.
I actually get this error no matter what kind of variable I try to pass bool, string, … (I the code above I’ve tried bool)
Thank you.