Beispiel #1
0
 def __init__(self, deadline, stop):
     self.deadline = deadline
     self.stop = stop
     self.timer = threadTimer(deadline, stop, args=None)
     self.acumTime = 0.0
     self.timer.start()
     self.startTime = time()
Beispiel #2
0
    def _eventPoster(self, event, rate):
        '''Posts events at the specified rate via a threadTimer.'''
        e = pyEvent
        if type(event) is not e.EventType:
            event = e.Event(event)

        def post(event):
            if self.__running:
                post_event(event)
                postThread.run()
                if not postThread.daemon:
                    postThread.daemon = True

        postThread = threadTimer(float(rate - 1) / 1000.0,
                                 post,
                                 args=(event, ))
        postThread.daemon = True
        postThread.start()
Beispiel #3
0
    def set_timer(self, event, rate, delay=0):
        '''Sets a timer for an event. Each event object will only have one
        timer associated with it. Setting a timers rate to 0 will stop it.'''
        if floor(delay) > 0:
            delayTimer = threadTimer(float(delay - 1) / 1000.0,
                                     self.set_timer,
                                     args=(event, rate))
            delayTimer.daemon = True
            delayTimer.start()
            return

        t = Timer(event, rate)
        for e in self.__timers:
            if e.get_event() == event:
                if floor(rate) > 0:
                    e.change_rate(rate)
                else:
                    e.stop_timer()
                    self.__timers.remove(e)
                return
        if floor(rate) > 0:
            t.start_timer()
            self.__timers.append(t)
Beispiel #4
0
 def resume(self):
     self.timer = threadTimer(self.deadline - (self.acumTime),
                              self.stop,
                              args=None)
     self.startTime = time()
     self.timer.start()