diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-11-22 12:13:09 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-11-22 12:13:09 +0100 |
commit | 392fb0aa63d08789ebb3be7c46c8dd6822f3f1a1 (patch) | |
tree | 1ab3f4712d04e2e1a0772a4ace166b29e43c96f3 /pyload/plugins | |
parent | Merge pull request #414 from vuolter/m/c_logging (diff) | |
parent | initPeriodical calls startPeriodical if periodcal was overwritten (diff) | |
download | pyload-392fb0aa63d08789ebb3be7c46c8dd6822f3f1a1.tar.xz |
Merge pull request #216 from vuolter/m/periodical
Improved periodical
Diffstat (limited to 'pyload/plugins')
-rw-r--r-- | pyload/plugins/Addon.py | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/pyload/plugins/Addon.py b/pyload/plugins/Addon.py index ee8cbe62c..d0ddfbca4 100644 --- a/pyload/plugins/Addon.py +++ b/pyload/plugins/Addon.py @@ -108,8 +108,32 @@ class Addon(Base): self.init() def initPeriodical(self): - if self.interval >=1: - self.cb = self.core.scheduler.addJob(0, self._periodical, threaded=False) + if id(self.periodical) != id(getattr(Addon, periodical)): + self.startPeriodical() + + def startPeriodical(self, interval=self.interval, wait=self.interval): + if not self.cb and self.setInterval(interval, False): + self.cb = self.core.scheduler.addJob(wait, self._periodical, threaded=False) + return interval + else: + return False + + def stopPeriodical(self): + if self.cb and self.core.scheduler.removeJob(self.cb): + self.cb = None + return True + else: + return False + + def setInterval(self, interval, recount=False): + if interval > 0: + if recount: + return self.stopPeriodical() and self.startPeriodical(interval) + else: + self.interval = interval + return True + else: + return False def _periodical(self): try: @@ -119,7 +143,8 @@ class Addon(Base): if self.core.debug: print_exc() - self.cb = self.core.scheduler.addJob(self.interval, self._periodical, threaded=False) + if self.cb: + self.cb = self.core.scheduler.addJob(self.interval, self._periodical, threaded=False) def __repr__(self): return "<Addon %s>" % self.__name__ |