In my Python rule, I often use recursive timers in the form of (cut down class and rule definition):
class HueGroupMgr(object): **** class other stuff *** def getFromBridge(self): *** do some stuff *** self.poll_timer = Timer(POLL_INTERVAL, lambda: self.getFromBridge()) self.poll_timer.start() def cleanUpTimers(self): if self.poll_timer != None: self.poll_timer.cancel() hueGroupMgr = HueGroupMgr() @rule("Hue Group Manager Rule", description="This is an rule for adding groups support for hue groups") class HueGroupsRule(object): def __init__(self): self.triggers = hueGroupMgr.getAllTriggers() def execute(self, module, inputs): hueGroupMgr.execute(module, inputs) def scriptUnloaded(): log.info("************* Unload HueGroupsRule ********* ") hueGroupMgr.cleanUpTimers()
It seems that although I have a cleaning up timers called by scriptUnloaded sometimes the recursive timer stays active and survives a code reload (saving a new version of code). During developing and debugging this drives me sometimes crazy.
2 Options: Making this code race condition safe, or manually restart the NGRE.
I have some ideas about what could solve the race condition, what I like to ask is how is it possible to restart the NGRE.
I looked at bundle:list but did not find any candidate to restart wit bundle:restart.