Search code examples
volttron

how to change number of @Core.periodic(30)


I make a new agent, and I will call every 30 seconds through Core.periodic(30).

And I write such as @Core.periodic(self.heart_beat), but this is not operate. (heart_beat is config file's variable.)

I don't know how to solve it.

enter image description here


Solution

  • @Core.periodic is a decorator (you can tell by the @ at the start of the line). It is supposed to be used like this:

    @Core.periodic(30)
    def heart_beat(self):
        #Do heartbeat stuff here
    

    If you need to do something dynamic you can hook up the callback during run time with self.core.periodic. This allows you to change the setting dynamically and stop the periodic function later if needed.

    self.heart_beat_greenlet = self.core.periodic(30, self.heart_beat)
    

    Later you can call self.heart_beat_greenlet.kill() to stop the periodic function.