removed deamon in TaskExecutor Thread and stopped manually according to "shutdown_wait" in core
This commit is contained in:
parent
c2d8da3cad
commit
e0bd6ad0ea
2 changed files with 9 additions and 5 deletions
|
|
@ -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__":
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue