From f934891b0d55d3882859e3d92e178b2d81ecc5a3 Mon Sep 17 00:00:00 2001 From: Stephan Reichholf Date: Sat, 10 Nov 2012 17:48:40 +0100 Subject: [PATCH] EPGRefresh/AutoTimer: another fix for epgrefresh & autotimer, it works for me now, please report! --- autotimer/src/AutoPoller.py | 8 +++++--- autotimer/src/AutoTimer.py | 2 +- epgrefresh/src/EPGRefresh.py | 32 +++++++++++++++++++++----------- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/autotimer/src/AutoPoller.py b/autotimer/src/AutoPoller.py index aa8573b5..317a7bdb 100644 --- a/autotimer/src/AutoPoller.py +++ b/autotimer/src/AutoPoller.py @@ -17,6 +17,8 @@ SIMILARNOTIFICATIONID = 'AutoTimerSimilarUsedNotification' from threading import Thread, Semaphore from collections import deque +from twisted.internet import reactor + class AutoPollerThread(Thread): """Background thread where the EPG is parsed (unless initiated by the user).""" def __init__(self): @@ -92,8 +94,8 @@ class AutoPollerThread(Thread): # Dump error to stdout import traceback, sys traceback.print_exc(file=sys.stdout) - - timer.startLongTimer(config.plugins.autotimer.interval.value*3600) + #Keep that eTimer in the mainThread + reactor.callFromThread(timer.startLongTimer, config.plugins.autotimer.interval.value*3600) class AutoPoller: """Manages actual thread which does the polling. Used for convenience.""" @@ -109,6 +111,6 @@ class AutoPoller: def stop(self): self.thread.stop() - # NOTE: while we don't need to join the thread, we should do so in case it's currently parsining + # NOTE: while we don't need to join the thread, we should do so in case it's currently parsing self.thread.join() self.thread = None diff --git a/autotimer/src/AutoTimer.py b/autotimer/src/AutoTimer.py index b2303845..f5c02c37 100644 --- a/autotimer/src/AutoTimer.py +++ b/autotimer/src/AutoTimer.py @@ -156,7 +156,7 @@ class AutoTimer: idx += 1 self.timers.append(timer) - def parseEPGAsync(self, simulateOnly=False): + def parseEPGAsync(self, simulateOnly = False): t = SimpleThread(lambda: self.parseEPG(simulateOnly=simulateOnly)) t.start() return t.deferred diff --git a/epgrefresh/src/EPGRefresh.py b/epgrefresh/src/EPGRefresh.py index b447eb21..82f650d8 100644 --- a/epgrefresh/src/EPGRefresh.py +++ b/epgrefresh/src/EPGRefresh.py @@ -32,6 +32,7 @@ from Components.config import config # MessageBox from Screens.MessageBox import MessageBox from Tools import Notifications +from Tools.BoundFunction import boundFunction # ... II from . import _, NOTIFICATIONID @@ -292,14 +293,29 @@ class EPGRefresh: autotimer = AutoTimer() # Parse EPG - autotimer.parseEPGAsync() + autotimer.parseEPGAsync(simulateOnly=False).addCallback( boundFunction(self.finish, removeInstance=removeInstance) ) + return except Exception as e: print("[EPGRefresh] Could not start AutoTimer:", e) - finally: - # Remove instance if there wasn't one before - if removeInstance: - autotimer = None + self.finish() + + def finish(self, *args, **kwargs): + removeInstance=kwargs.get("removeInstance") + if not Screens.Standby.inStandby and not config.plugins.epgrefresh.background and config.plugins.epgrefresh.enablemessage.value: + Notifications.AddPopup(_("EPG refresh finished."), MessageBox.TYPE_INFO, 4, NOTIFICATIONID) + self.forcedScan = False + epgrefreshtimer.cleanup() + self.maybeStopAdapter() + + # Remove instance if there wasn't one before + if removeInstance: + try: + # Import Instance + from Plugins.Extensions.AutoTimer.plugin import autotimer + autotimer = None + except: + pass # shutdown if we're supposed to go to deepstandby and not recording if not self.forcedScan and config.plugins.epgrefresh.afterevent.value \ and not Screens.Standby.inTryQuitMainloop: @@ -309,12 +325,6 @@ class EPGRefresh: 1 ) - if not Screens.Standby.inStandby and not config.plugins.epgrefresh.background and config.plugins.epgrefresh.enablemessage.value: - Notifications.AddPopup(_("EPG refresh finished."), MessageBox.TYPE_INFO, 4, NOTIFICATIONID) - self.forcedScan = False - epgrefreshtimer.cleanup() - self.maybeStopAdapter() - def refresh(self): if self.forcedScan: self.nextService() -- 2.20.1