Task that executes every so many seconds

Does someone have some advice on how to design a task which will continually update every 5 seconds?

I have the following code but I’m not sure what to do with task.time.

    def CheckNeedsTask(self, task):
        if (task.time%5>4.9):            
        #print str(task.time%5)
        return Task.cont

I just found a solution. I just stop the task every 5 seconds then in my cleanup function I just add it back to the taskMgr which restarts the task.frame timer. Is there a better way?

The magic is in returning task.again, which is similar to task.cont except that it means run the task again, not immediately, but after the same delay that ran it in the first place.

def myTask(self, task):
    # do stuff
    return task.again

taskMgr.doMethodLater(5, self.myTask, 'myTask')


Great. Thank you.