clean way to add timers in python?

I’m wondering if there is an easy way to create new timers via python in the game engine. I’ve done my share of searches, and so far the best method I’ve been able to come up with is using the Timer() object from the Python standard threading module, but I figure that this is probably adding some unnecessary overhead.

Is there a better/preferred method for adding timer objects in the game engine?

That is a bit more complex - I would just make a normal number variable, and add a time value each frame. If you want a time value, divide 1 by the logic tic rate:

from bge import logic

cont = logic.getCurrentController()
obj = cont.owner

if not 'timer' in obj:
     obj['timer'] = 0.0

obj['timer'] += 1.0 / logic.getLogicTicRate()

Thanks, that helps a lot. I wish there was a way to create timers that didn’t require manual updates, but this is certainly an improvement.

Creating timers manually would be a nice addition, I suppose, but this method’s not that bad. You could even create a function to create timers (in a list, for example) and update them automatically, then run a callback kind of function when a timer runs out (if you don’t want to manually handle the time yourself).