From 42d149b40fc3a4443133a2369c2a2b0a184660d0 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 6 Sep 2025 23:37:48 -0400 Subject: [PATCH] motion_queuing: Avoid flushing far into the future If a flush_all_steps() request is for a time far in the future, then wait for that time to become close prior to flushing steps. This avoids committing to a step schedule that is far in the future. Signed-off-by: Kevin O'Connor --- klippy/extras/motion_queuing.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/klippy/extras/motion_queuing.py b/klippy/extras/motion_queuing.py index 67609eee7..d85f173c4 100644 --- a/klippy/extras/motion_queuing.py +++ b/klippy/extras/motion_queuing.py @@ -180,8 +180,20 @@ class PrinterMotionQueuing: self.last_step_gen_time = step_gen_time if flush_time >= want_flush_time: break + def _await_flush_time(self, want_flush_time): + while 1: + if self.last_flush_time >= want_flush_time or not self.can_pause: + return + systime = self.reactor.monotonic() + est_print_time = self.mcu.estimated_print_time(systime) + wait = want_flush_time - BGFLUSH_HIGH_TIME - est_print_time + if wait <= 0.: + return + self.reactor.pause(systime + min(1., wait)) def flush_all_steps(self): - self._advance_flush_time(self.need_step_gen_time) + flush_time = self.need_step_gen_time + self._await_flush_time(flush_time) + self._advance_flush_time(flush_time) def calc_step_gen_restart(self, est_print_time): kin_time = max(est_print_time + MIN_KIN_TIME, self.last_step_gen_time) return kin_time + self.kin_flush_delay @@ -254,9 +266,11 @@ class PrinterMotionQueuing: self.do_kick_flush_timer = False self.reactor.update_timer(self.flush_timer, self.reactor.NOW) def drip_update_time(self, start_time, end_time, drip_completion): + self._await_flush_time(start_time) # Disable background flushing from timer self.reactor.update_timer(self.flush_timer, self.reactor.NEVER) self.do_kick_flush_timer = False + self._advance_flush_time(start_time) # Flush in segments until drip_completion signal flush_time = start_time while flush_time < end_time: