From d701c261c36db761d17817be60b1ec858366e5a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 11 Mar 2016 12:35:53 +0100 Subject: [PATCH] Less processing overhead when uploading to SD Better structured "don't handle phases" checks and adjusted job wrapper that doesn't try to apply tool tracking or temperature offsets. --- src/octoprint/util/comm.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 0db2e0a9..da7bd4f7 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -1662,24 +1662,22 @@ class MachineCom(object): return False gcode = None - if not self.isStreaming(): - # trigger the "queuing" phase only if we are not streaming to sd right now - cmd, cmd_type, gcode = self._process_command_phase("queuing", cmd, cmd_type, gcode=gcode) - if cmd is None: - # command is no more, return - return False + # trigger the "queuing" phase only if we are not streaming to sd right now + cmd, cmd_type, gcode = self._process_command_phase("queuing", cmd, cmd_type, gcode=gcode) - if gcode and gcode in gcodeToEvent: - # if this is a gcode bound to an event, trigger that now - eventManager().fire(gcodeToEvent[gcode]) + if cmd is None: + # command is no more, return + return False + + if not self.isStreaming() and gcode and gcode in gcodeToEvent: + # if this is a gcode bound to an event, trigger that now + eventManager().fire(gcodeToEvent[gcode]) # actually enqueue the command for sending self._enqueue_for_sending(cmd, command_type=cmd_type) - if not self.isStreaming(): - # trigger the "queued" phase only if we are not streaming to sd right now - self._process_command_phase("queued", cmd, cmd_type, gcode=gcode) + self._process_command_phase("queued", cmd, cmd_type, gcode=gcode) return True @@ -1781,7 +1779,7 @@ class MachineCom(object): self._log("Closing down send loop") def _process_command_phase(self, phase, command, command_type=None, gcode=None): - if phase not in ("queuing", "queued", "sending", "sent"): + if self.isStreaming() or phase not in ("queuing", "queued", "sending", "sent"): return command, command_type, gcode if gcode is None: @@ -2234,8 +2232,7 @@ class PrintingGcodeFileInformation(PrintingFileInformation): line = to_unicode(self._handle.readline()) if not line: self.close() - processed = process_gcode_line(line, offsets=offsets, current_tool=current_tool) - + processed = self._process(line, offsets, current_tool) self._pos = self._handle.tell() self._read_lines += 1 return processed @@ -2244,6 +2241,9 @@ class PrintingGcodeFileInformation(PrintingFileInformation): self._logger.exception("Exception while processing line") raise e + def _process(self, line, offsets, current_tool): + return process_gcode_line(line, offsets=offsets, current_tool=current_tool) + def _report_stats(self): duration = time.time() - self._start_time stats = dict(lines=self._read_lines, @@ -2268,6 +2268,9 @@ class StreamingGcodeFileInformation(PrintingGcodeFileInformation): def getRemoteFilename(self): return self._remoteFilename + def _process(self, line, offsets, current_tool): + return process_gcode_line(line) + class TypedQueue(queue.Queue):