diff --git a/SickBeard.py b/SickBeard.py index 7cd279b6..8da08582 100755 --- a/SickBeard.py +++ b/SickBeard.py @@ -390,7 +390,7 @@ def main(): # check for commands to be executed in the background task = PeriodicCallback(invoke_command, 1000) - task.start() + sickbeard.WEBSERVER.tasks.append(task) # start tornado sickbeard.WEBSERVER.start() diff --git a/sickbeard/__init__.py b/sickbeard/__init__.py index 4eb788af..8ebf4c8e 100644 --- a/sickbeard/__init__.py +++ b/sickbeard/__init__.py @@ -1117,12 +1117,15 @@ def start(): showUpdateScheduler, versionCheckScheduler, showQueueScheduler, \ properFinderScheduler, autoPostProcesserScheduler, searchQueueScheduler, \ subtitlesFinderScheduler, USE_SUBTITLES,traktWatchListCheckerScheduler, \ - dailySearchScheduler, started + dailySearchScheduler, WEBSERVER, started with INIT_LOCK: if __INITIALIZED__: + # start IOLoop tasks + WEBSERVER.start_tasks() + # start the maintenance scheduler maintenanceScheduler.thread.start() logger.log(u"Performing initial maintenance tasks, please wait ...") @@ -1168,7 +1171,7 @@ def halt(): showUpdateScheduler, versionCheckScheduler, showQueueScheduler, \ properFinderScheduler, autoPostProcesserScheduler, searchQueueScheduler, \ subtitlesFinderScheduler, traktWatchListCheckerScheduler, \ - dailySearchScheduler, started + dailySearchScheduler, WEBSERVER, started with INIT_LOCK: @@ -1178,6 +1181,8 @@ def halt(): # abort all the threads + WEBSERVER.stop_tasks() + maintenanceScheduler.abort = True logger.log(u"Waiting for the MAINTENANCE scheduler thread to exit") try: diff --git a/sickbeard/webserveInit.py b/sickbeard/webserveInit.py index 83408c12..d2d0f0ff 100644 --- a/sickbeard/webserveInit.py +++ b/sickbeard/webserveInit.py @@ -40,6 +40,7 @@ class webserverInit(): self.server = None self.ioloop = None + self.tasks = [] self.options = options self.options.setdefault('port', 8081) @@ -155,4 +156,12 @@ class webserverInit(): self.ioloop.stop() def close(self): - self.ioloop.close() \ No newline at end of file + self.ioloop.close() + + def start_tasks(self): + for task in self.tasks: + task.start() + + def stop_tasks(self): + for task in self.tasks: + task.stop()