From e0bd6ad0ea57f7b989f92d02313209397ef9d4dd Mon Sep 17 00:00:00 2001 From: RafTim Date: Sat, 9 Nov 2013 02:42:51 +0100 Subject: [PATCH] removed deamon in TaskExecutor Thread and stopped manually according to "shutdown_wait" in core --- bin/linspector | 5 ++++- linspector/tasks/task.py | 9 +++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/bin/linspector b/bin/linspector index d476d9b..cba15c1 100755 --- a/bin/linspector +++ b/bin/linspector @@ -158,13 +158,16 @@ def main(): logger.debug("shutting down scheduler") - shutdown_wait = True if "shutdown_wait" in core: shutdown_wait = core["shutdown_wait"] scheduler.shutdown(wait=shutdown_wait) logging.shutdown() + if shutdown_wait: + TaskExecutor.Instance().stop() + else: + TaskExecutor.Instance().stop_immediately() if __name__ == "__main__": diff --git a/linspector/tasks/task.py b/linspector/tasks/task.py index 7b47045..04aecfe 100644 --- a/linspector/tasks/task.py +++ b/linspector/tasks/task.py @@ -73,14 +73,13 @@ class TaskExecutor(object): self.event = Event() self.taskInfos = [] task_thread = Thread(target=self._run_worker_thread) - task_thread.setDaemon(True) self._instantEnd = False self._running = True task_thread.start() def _run_worker_thread(self): - while self.is_running() or not self.instand_end(): + while self.is_running() or not self.is_instant_end(): if len(self.taskInfos) == 0: self.event.clear() self.event.wait() @@ -95,7 +94,7 @@ class TaskExecutor(object): except Exception, e: logger.error("Error " + str(e)) - def is_instand_end(self): + def is_instant_end(self): return self._instantEnd def is_running(self): @@ -103,10 +102,12 @@ class TaskExecutor(object): def stop(self): self._running = False + self.event.set() def stop_immediately(self): - self.stop() + self._running = False self._instantEnd = True + self.event.set() def schedule_task(self, msg, task): self.taskInfos.append((msg, task))