diff --git a/dbgpt/app/initialization/scheduler.py b/dbgpt/app/initialization/scheduler.py index 33dd220eb..70b7bb71a 100644 --- a/dbgpt/app/initialization/scheduler.py +++ b/dbgpt/app/initialization/scheduler.py @@ -24,6 +24,7 @@ def __init__( self.system_app = system_app self._scheduler_interval_ms = scheduler_interval_ms self._scheduler_delay_ms = scheduler_delay_ms + self._stop_event = threading.Event() def init_app(self, system_app: SystemApp): self.system_app = system_app @@ -31,10 +32,14 @@ def init_app(self, system_app: SystemApp): def after_start(self): thread = threading.Thread(target=self._scheduler) thread.start() + self._stop_event.clear() + + def before_stop(self): + self._stop_event.set() def _scheduler(self): time.sleep(self._scheduler_delay_ms / 1000) - while True: + while not self._stop_event.is_set(): try: schedule.run_pending() except Exception as e: