I browsed to forum but couldn’t find anything on that subject. Here is my proble : I need to listen to a data source every x minutes. The data source (a simple table in a database) is uploaded every X minutes by another script. With the data collected, I want to create objects in Panda3D, etc etc…
How can I create a function or a method that will be launched every X minutes ?
I use a task in my myasterserver to check if the game servers are still alive and update the sql DB every 10 minutes (600 seconds)
It looks like this:
import time
self.tmpTime=0
def controlTask(self, task):
if (time.time() >= self.tmpTime):
self.tmpTime = time.time()+600
print "Checking Servers"
self.refreshServers()
return Task.cont
I’m using the system time to determine if 10 minutes have passed, though you could also do it with the task time.
Anyway, this method is proved to work properly.
The format of the system time (time.time() ) is in Unix time (that is the time in seconds since the first Unix was born -somewhere back in the 1970ies)
Thanks everyone ! I asked my question on IRc and thomasEgi answered me. And I already did what I wanted to do with his method. Sorry to have forgot to say that my problem is solved.
Just a small precision : TE said that with his method, the method is executed every x seconds. It’s not true. What really happens is that there is x seconds between the end of a call and the beginning of the second one. Depending on the method it can be very different.