diff --git a/fHDHR/cli/run.py b/fHDHR/cli/run.py index 778c6ea..49be508 100644 --- a/fHDHR/cli/run.py +++ b/fHDHR/cli/run.py @@ -52,13 +52,6 @@ def run(settings, logger, db, script_dir, fHDHR_web, origin, alternative_epg): if settings.dict["main"]["thread_method"] in ["multiprocessing", "threading"]: fhdhr_web.start() - # Perform some actions now that HTTP Server is running, but don't wait for response - # Hit EPG Update API URL without waiting - try: - fhdhr.web.session.get("%s/api/startup_tasks" % (fhdhr.api.base)) - except fhdhr.web.exceptions.ReadTimeout: - pass - if settings.dict["fhdhr"]["discovery_address"]: fhdhr.logger.info("SSDP Server Starting") if settings.dict["main"]["thread_method"] in ["multiprocessing"]: @@ -69,7 +62,7 @@ def run(settings, logger, db, script_dir, fHDHR_web, origin, alternative_epg): fhdhr_ssdp.start() if settings.dict["epg"]["method"]: - fhdhr.logger.info("EPG Update Starting") + fhdhr.logger.info("EPG Update Thread Starting") if settings.dict["main"]["thread_method"] in ["multiprocessing"]: fhdhr_epg = multiprocessing.Process(target=fhdhr.device.epg.run) elif settings.dict["main"]["thread_method"] in ["threading"]: @@ -77,6 +70,18 @@ def run(settings, logger, db, script_dir, fHDHR_web, origin, alternative_epg): if settings.dict["main"]["thread_method"] in ["multiprocessing", "threading"]: fhdhr_epg.start() + # Perform some actions now that HTTP Server is running, but don't wait for response + # Hit EPG Update API URL without waiting + fhdhr.logger.info("Waiting 3 seconds to send startup tasks trigger.") + time.sleep(3) + try: + fhdhr.web.session.get("%s/api/startup_tasks" % (fhdhr.api.base)) + except fhdhr.web.exceptions.ReadTimeout: + pass + except fhdhr.web.exceptions.ConnectionError as e: + fhdhr.logger.warning("Startup tasks failed: %s" % e) + pass + # wait forever while True: time.sleep(3600) diff --git a/fHDHR/device/epg/__init__.py b/fHDHR/device/epg/__init__.py index a7b1ea0..0ad4575 100644 --- a/fHDHR/device/epg/__init__.py +++ b/fHDHR/device/epg/__init__.py @@ -296,10 +296,18 @@ class EPG(): while True: for epg_method in self.epg_methods: last_update_time = self.fhdhr.db.get_fhdhr_value("update_time", epg_method) + updatetheepg = False if not last_update_time: - self.fhdhr.web.session.get(self.epg_update_url) + updatetheepg = True elif time.time() >= (last_update_time + self.sleeptime[epg_method]): - self.fhdhr.web.session.get(self.epg_update_url) - time.sleep(360) + updatetheepg = True + if updatetheepg: + try: + self.fhdhr.web.session.get(self.epg_update_url, timeout=0.0000000001) + except self.fhdhr.web.exceptions.ReadTimeout: + pass + except self.fhdhr.web.exceptions.ConnectionError as e: + self.fhdhr.logger.error("Error updating %s EPG cache: %s" % (epg_method, e)) + time.sleep(1800) except KeyboardInterrupt: pass