From 0d13834293d0b5db2fc3407bd603dbfaa691402d Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 2 Sep 2017 11:47:22 -0400 Subject: [PATCH] gcode: Fix error that could cause commands to be processed out of order Commit d0932009 changed the way command handling was performed, and commit 95950949 fixed a defect in that commit. Unfortunately, the fix was incomplete. If multiple commands were sent to Klippy without waiting for an "ok" response from Klippy, then it was possible for those additional commands to be queued and processed after subsequent commands. This would result in commands being processed out of order. Fix this by only reregistering the input fd in the greenlet that performs the unregistration of the fd. Signed-off-by: Kevin O'Connor --- klippy/gcode.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/klippy/gcode.py b/klippy/gcode.py index d3af9731..c66b74c5 100644 --- a/klippy/gcode.py +++ b/klippy/gcode.py @@ -126,15 +126,15 @@ class GCodeParser: lines[0] = self.partial_input + lines[0] self.partial_input = lines.pop() if self.is_processing_data: - if not self.is_fileinput: - if not lines: - return - if lines[0].strip().upper() == 'M112': - self.cmd_M112({}) + if not self.is_fileinput and not lines: + return self.reactor.unregister_fd(self.fd_handle) self.fd_handle = None + if not self.is_fileinput and lines[0].strip().upper() == 'M112': + self.cmd_M112({}) while self.is_processing_data: eventtime = self.reactor.pause(eventtime + 0.100) + self.fd_handle = self.reactor.register_fd(self.fd, self.process_data) self.is_processing_data = True self.process_commands(lines) if not data and self.is_fileinput: @@ -143,8 +143,6 @@ class GCodeParser: self.toolhead.wait_moves() self.printer.request_exit() self.is_processing_data = False - if self.fd_handle is None: - self.fd_handle = self.reactor.register_fd(self.fd, self.process_data) # Response handling def ack(self, msg=None): if not self.need_ack or self.is_fileinput: