From 0b7686445376ace8a32c729d05c690818b319b29 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 2 Feb 2018 18:28:48 -0500 Subject: [PATCH] gcode: Make sure need_ack is always restored on run_script() Restore need_ack even on a G-Code exception. Signed-off-by: Kevin O'Connor --- klippy/gcode.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/klippy/gcode.py b/klippy/gcode.py index 38ff348a..21a27252 100644 --- a/klippy/gcode.py +++ b/klippy/gcode.py @@ -135,7 +135,6 @@ class GCodeParser: # Parse input into commands args_r = re.compile('([A-Z_]+|[A-Z*])') def process_commands(self, commands, need_ack=True): - prev_need_ack = self.need_ack for line in commands: # Ignore comments and leading/trailing spaces line = origline = line.strip() @@ -172,7 +171,6 @@ class GCodeParser: if not need_ack: raise self.ack() - self.need_ack = prev_need_ack m112_r = re.compile('^(?:[nN][0-9]+)?\s*[mM]112(?:\s|$)') def process_data(self, eventtime): # Read input, separate by newline, and add to pending_commands @@ -213,7 +211,11 @@ class GCodeParser: self.toolhead.wait_moves() self.printer.request_exit() def run_script(self, script): - self.process_commands(script.split('\n'), need_ack=False) + prev_need_ack = self.need_ack + try: + self.process_commands(script.split('\n'), need_ack=False) + finally: + self.need_ack = prev_need_ack # Response handling def ack(self, msg=None): if not self.need_ack or self.is_fileinput: