diff options
author | Walter Purcaro <vuolter@gmail.com> | 2013-08-02 17:16:29 +0200 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2013-11-16 17:40:10 +0100 |
commit | b565853e311eb480212f0743ac6d8e0914a09a9c (patch) | |
tree | 5db50da26cf034ed86a84c6ffff213eb470e5ff2 /pyload/plugins/Addon.py | |
parent | Merge pull request #365 from vuolter/m/timestamp (diff) | |
download | pyload-b565853e311eb480212f0743ac6d8e0914a09a9c.tar.xz |
Improved addon periodic call
Diffstat (limited to 'pyload/plugins/Addon.py')
-rw-r--r-- | pyload/plugins/Addon.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/pyload/plugins/Addon.py b/pyload/plugins/Addon.py index ee8cbe62c..50a38960a 100644 --- a/pyload/plugins/Addon.py +++ b/pyload/plugins/Addon.py @@ -78,7 +78,7 @@ class Addon(Base): event_map = None #: periodic call interval in seconds - interval = 60 + interval = 30 def __init__(self, core, manager, user=None): Base.__init__(self, core, user) @@ -104,12 +104,21 @@ class Addon(Base): #delete for various reasons self.event_map = None - self.initPeriodical() + #self.initPeriodical() self.init() - def initPeriodical(self): - if self.interval >=1: - self.cb = self.core.scheduler.addJob(0, self._periodical, threaded=False) + def stopPeriodical(self): + if not self.cb: + return + r = self.core.scheduler.removeJob(self.cb) + self.cb = None + return r #: return True if successfully removed else False + + def initPeriodical(self, wait=0): + if self.interval > 0: + self.cb = self.core.scheduler.addJob(wait, self._periodical, threaded=False) + else: + self.stopPeriodical() def _periodical(self): try: @@ -119,7 +128,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__ |