Merge branch 'master' of github.com:linspector/linspector

This commit is contained in:
Johannes Findeisen 2013-11-09 03:47:25 +01:00
commit b0f974ad9c
2 changed files with 9 additions and 5 deletions

View file

@ -158,13 +158,16 @@ def main():
logger.debug("shutting down scheduler") logger.debug("shutting down scheduler")
shutdown_wait = True shutdown_wait = True
if "shutdown_wait" in core: if "shutdown_wait" in core:
shutdown_wait = core["shutdown_wait"] shutdown_wait = core["shutdown_wait"]
scheduler.shutdown(wait=shutdown_wait) scheduler.shutdown(wait=shutdown_wait)
logging.shutdown() logging.shutdown()
if shutdown_wait:
TaskExecutor.Instance().stop()
else:
TaskExecutor.Instance().stop_immediately()
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -76,13 +76,12 @@ class TaskExecutor(object):
self.event = Event() self.event = Event()
self.taskInfos = [] self.taskInfos = []
task_thread = Thread(target=self._run_worker_thread) task_thread = Thread(target=self._run_worker_thread)
task_thread.setDaemon(True)
self._instantEnd = False self._instantEnd = False
self._running = True self._running = True
task_thread.start() task_thread.start()
def _run_worker_thread(self): 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: if len(self.taskInfos) == 0:
self.event.clear() self.event.clear()
self.event.wait() self.event.wait()
@ -105,11 +104,13 @@ class TaskExecutor(object):
def stop(self): def stop(self):
self._running = False self._running = False
self.event.set()
def stop_immediately(self): def stop_immediately(self):
self.stop() self._running = False
self._instantEnd = True self._instantEnd = True
self.event.set()
def schedule_task(self, msg, task): def schedule_task(self, msg, task):
self.taskInfos.append((msg, task)) self.taskInfos.append((msg, task))
self.event.set() self.event.set()