aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/gcode.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2018-10-18 11:51:35 -0400
committerKevin O'Connor <kevin@koconnor.net>2018-10-28 18:39:45 -0400
commita5e55c2acc2650c70acd6bf852810e30fb959f96 (patch)
treecdf0c9cbb9f5b3000ee92ad3c3f46d09f652308f /klippy/gcode.py
parent37b9a2442ff661e736c15ae6ee5d1f1bcebd7b8d (diff)
downloadkutter-a5e55c2acc2650c70acd6bf852810e30fb959f96.tar.gz
kutter-a5e55c2acc2650c70acd6bf852810e30fb959f96.tar.xz
kutter-a5e55c2acc2650c70acd6bf852810e30fb959f96.zip
gcode: process_batch() should execute commands atomically
Update the process_batch() method so that it will not interleave commands read from the input fd with the batched commands. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/gcode.py')
-rw-r--r--klippy/gcode.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/klippy/gcode.py b/klippy/gcode.py
index f6f8796a..06a2fd48 100644
--- a/klippy/gcode.py
+++ b/klippy/gcode.py
@@ -247,16 +247,20 @@ class GCodeParser:
pending_commands = self.pending_commands
if self.fd_handle is None:
self.fd_handle = self.reactor.register_fd(self.fd, self.process_data)
- def process_batch(self, command):
+ def process_batch(self, commands):
if self.is_processing_data:
return False
self.is_processing_data = True
try:
- self.process_commands([command], need_ack=False)
- finally:
+ self.process_commands(commands, need_ack=False)
+ except error as e:
if self.pending_commands:
self.process_pending()
self.is_processing_data = False
+ raise
+ if self.pending_commands:
+ self.process_pending()
+ self.is_processing_data = False
return True
def run_script_from_command(self, script):
prev_need_ack = self.need_ack
@@ -265,16 +269,15 @@ class GCodeParser:
finally:
self.need_ack = prev_need_ack
def run_script(self, script):
- curtime = self.reactor.monotonic()
- for line in script.split('\n'):
- while 1:
- try:
- res = self.process_batch(line)
- except:
- break
- if res:
- break
- curtime = self.reactor.pause(curtime + 0.100)
+ commands = script.split('\n')
+ curtime = None
+ while 1:
+ res = self.process_batch(commands)
+ if res:
+ break
+ if curtime is None:
+ curtime = self.reactor.monotonic()
+ curtime = self.reactor.pause(curtime + 0.100)
# Response handling
def ack(self, msg=None):
if not self.need_ack or self.is_fileinput: