def newTimer(self,
                 interval: float,
                 func: str,
                 args: list = None,
                 autoStart: bool = True) -> threading.Timer:
        if not args:
            args = list()

        threadTimer = ThreadTimer(callback=func, args=args)
        t = threading.Timer(interval=interval,
                            function=self.onTimerEnd,
                            args=[threadTimer])
        t.daemon = True
        threadTimer.timer = t
        self._timers.append(threadTimer)

        if autoStart:
            t.start()

        return t
Exemple #2
0
    def newTimer(self,
                 interval: float,
                 func: Callable,
                 autoStart: bool = True,
                 args: list = None,
                 kwargs: dict = None) -> threading.Timer:
        args = args or list()
        kwargs = kwargs or dict()

        threadTimer = ThreadTimer(callback=func, args=args, kwargs=kwargs)
        timer = threading.Timer(interval=interval,
                                function=self.onTimerEnd,
                                args=[threadTimer])
        timer.daemon = True
        threadTimer.timer = timer
        self._timers.append(threadTimer)

        if autoStart:
            timer.start()

        return timer
 def onTimerEnd(self, t: ThreadTimer):
     t.callback(*t.args, **t.kwargs)
     self.removeTimer(t)
Exemple #4
0
    def onTimerEnd(self, timer: ThreadTimer):
        if not timer or not timer.callback:
            return

        timer.callback(*timer.args, **timer.kwargs)
        self.removeTimer(timer)
    def onTimerEnd(self, t: ThreadTimer):
        if not t or not t.callback:
            return

        t.callback(*t.args, **t.kwargs)
        self.removeTimer(t)