fix: scheduler shutdown (#1237)

This commit is contained in:
Pol Bachelin 2024-03-02 14:35:00 +01:00 committed by GitHub
parent 505bc32775
commit 8565f64971
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -24,6 +24,7 @@ class DefaultScheduler(BaseComponent):
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 @@ class DefaultScheduler(BaseComponent):
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: