Check out the sched module in the Python standard library - as such, it does not support direct periodic timers, turning off "events", but it uses a standard trick to include a one-time event in a periodic timer (the called-time processing of a one-time event is simply reconfigured for the next repetition before proceeding to doing real work).
It may be convenient to define a "scheduled periodic timer" class to encapsulate key ideas:
class spt(object):
def __init__(self, scheduler, period):
self._sched = scheduler
self._period = period
self._event = None
def start(self):
self._event = self._sched.enter(0, 0, self._action, ())
def _action(self):
self._event - self._sched.enter(self._period, 0, self._action, ())
self.act()
def act(self):
print "hi there"
def cancel(self):
self._sched.cancel(self._event)
, spt act ( ). , , __init__ , ( self.scheduler) ( , time.time time.sleep); , (, 0), 0, .