Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGhostkeeper <rubend@tutanota.com>2020-05-11 18:36:24 +0300
committerGhostkeeper <rubend@tutanota.com>2020-05-11 18:36:24 +0300
commit1946615fff768bff4795bba5974f07315597c389 (patch)
tree87e7a18200ffff24c819fc8189a3f932d1e5b6b7 /plugins/USBPrinting
parent5ccf8e412d91f34bb850e61e489781ecd2efb6ad (diff)
Fix asynchronous bug if job gets cancelled
If the print job happens to get cancelled right after checking if the index is correct, but before actually reading the line, it would get an IndexError when trying to read the line since cancelling the job clears the _gcode list. This prevents that asynchronous issue by using the internal check in the list access to check that, and just uses an exception to check whether it's reached the end. Fixes Sentry issue CURA-QC.
Diffstat (limited to 'plugins/USBPrinting')
-rw-r--r--plugins/USBPrinting/USBPrinterOutputDevice.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/plugins/USBPrinting/USBPrinterOutputDevice.py b/plugins/USBPrinting/USBPrinterOutputDevice.py
index cf07b98ca1..6be3827e5e 100644
--- a/plugins/USBPrinting/USBPrinterOutputDevice.py
+++ b/plugins/USBPrinting/USBPrinterOutputDevice.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2019 Ultimaker B.V.
+# Copyright (c) 2020 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
import os
@@ -367,11 +367,18 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
self._sendCommand("M84")
def _sendNextGcodeLine(self):
- if self._gcode_position >= len(self._gcode):
+ """
+ Send the next line of g-code, at the current `_gcode_position`, via a
+ serial port to the printer.
+
+ If the print is done, this sets `_is_printing` to `False` as well.
+ """
+ try:
+ line = self._gcode[self._gcode_position]
+ except IndexError: # End of print, or print got cancelled.
self._printers[0].updateActivePrintJob(None)
self._is_printing = False
return
- line = self._gcode[self._gcode_position]
if ";" in line:
line = line[:line.find(";")]
@@ -401,7 +408,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
if print_job is None:
controller = GenericOutputController(self)
controller.setCanUpdateFirmware(True)
- print_job = PrintJobOutputModel(output_controller=controller, name=CuraApplication.getInstance().getPrintInformation().jobName)
+ print_job = PrintJobOutputModel(output_controller = controller, name = CuraApplication.getInstance().getPrintInformation().jobName)
print_job.updateState("printing")
self._printers[0].updateActivePrintJob(print_job)