summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-11-22 12:13:09 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-11-22 12:13:09 +0100
commit392fb0aa63d08789ebb3be7c46c8dd6822f3f1a1 (patch)
tree1ab3f4712d04e2e1a0772a4ace166b29e43c96f3
parentMerge pull request #414 from vuolter/m/c_logging (diff)
parentinitPeriodical calls startPeriodical if periodcal was overwritten (diff)
downloadpyload-392fb0aa63d08789ebb3be7c46c8dd6822f3f1a1.tar.xz
Merge pull request #216 from vuolter/m/periodical
Improved periodical
-rw-r--r--pyload/AddonManager.py3
-rw-r--r--pyload/plugins/Addon.py31
2 files changed, 30 insertions, 4 deletions
diff --git a/pyload/AddonManager.py b/pyload/AddonManager.py
index 7935ff112..d2dd25edc 100644
--- a/pyload/AddonManager.py
+++ b/pyload/AddonManager.py
@@ -139,7 +139,8 @@ class AddonManager:
self.log.debug("Plugin deactivated: %s" % plugin)
#remove periodic call
- self.log.debug("Removed callback %s" % self.core.scheduler.removeJob(addon.cb))
+ if addon.cb:
+ self.log.debug("Removed callback %s" % self.core.scheduler.removeJob(addon.cb))
del self.plugins[addon.__name__]
#remove event listener
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__