ソースを参照

Fix stop not interrupting motion thread retry loop

The motion thread's retry loop was checking stop_requested only before
sending commands, not at the start of each iteration or while waiting
for responses. This caused infinite "No 'ok' received" retries when
stop was requested.

Added stop checks at:
- Start of each retry iteration (immediate return)
- Inside response wait loop (escape blocking readline)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
tuanchris 6 ヶ月 前
コミット
d2d68be821
1 ファイル変更19 行追加11 行削除
  1. 19 11
      modules/core/pattern_manager.py

+ 19 - 11
modules/core/pattern_manager.py

@@ -429,18 +429,26 @@ class MotionControlThread:
         logger.debug(f"Motion thread sending G-code: X{x} Y{y} at F{speed}")
         logger.debug(f"Motion thread sending G-code: X{x} Y{y} at F{speed}")
 
 
         while True:
         while True:
+            # Check stop_requested at the start of each iteration
+            if state.stop_requested:
+                logger.debug("Motion thread: Stop requested, aborting command")
+                return
+
             try:
             try:
-                if not state.stop_requested:
-                    gcode = f"$J=G91 G21 Y{y} F{speed}" if home else f"G1 G53 X{x} Y{y} F{speed}"
-                    state.conn.send(gcode + "\n")
-                    logger.debug(f"Motion thread sent command: {gcode}")
-
-                    while True:
-                        response = state.conn.readline()
-                        logger.debug(f"Motion thread response: {response}")
-                        if response.lower() == "ok":
-                            logger.debug("Motion thread: Command execution confirmed.")
-                            return
+                gcode = f"$J=G91 G21 Y{y} F{speed}" if home else f"G1 G53 X{x} Y{y} F{speed}"
+                state.conn.send(gcode + "\n")
+                logger.debug(f"Motion thread sent command: {gcode}")
+
+                while True:
+                    # Also check stop_requested while waiting for response
+                    if state.stop_requested:
+                        logger.debug("Motion thread: Stop requested while waiting for response")
+                        return
+                    response = state.conn.readline()
+                    logger.debug(f"Motion thread response: {response}")
+                    if response.lower() == "ok":
+                        logger.debug("Motion thread: Command execution confirmed.")
+                        return
 
 
             except Exception as e:
             except Exception as e:
                 error_str = str(e)
                 error_str = str(e)