- 在循环启动时设置 last_run_time 以便外部调用者可预测地计算下次运行时间 - 添加异常处理以确保时间记录不会中断启动过程 - 更新时间记录逻辑以提高运行时间计算的准确性
@@ -79,6 +79,12 @@ class ProtectorRunner:
def start(self):
self._stop.clear()
+ # mark last_run_time when loop is started so external callers can compute
+ # next run time predictably (will be updated when run_once actually runs)
+ try:
+ self.last_run_time = time.time()
+ except Exception:
+ pass
def _loop():
while not self._stop.is_set():
# respect pause state