From 9de064fdba7cb5490b48979ad4b6b7f5743f0c07 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 9 Sep 2016 15:20:08 +0200 Subject: [PATCH 1/4] Fixed issue where large files could no longer be sent CURA-2286 --- NetworkPrinterOutputDevice.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NetworkPrinterOutputDevice.py b/NetworkPrinterOutputDevice.py index 4fef337b13..7bb1eb59d9 100644 --- a/NetworkPrinterOutputDevice.py +++ b/NetworkPrinterOutputDevice.py @@ -552,6 +552,8 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): if self._use_gzip: file_name = "%s.gcode.gz" % Application.getInstance().getPrintInformation().jobName single_string_file_data = gzip.compress(single_string_file_data.encode("utf-8")) + # Pretend that this is a response, as zipping might take a bit of time. + self._last_response_time = time() else: file_name = "%s.gcode" % Application.getInstance().getPrintInformation().jobName single_string_file_data = single_string_file_data.encode("utf-8") From 3747db0f4daf4759e4025907981baec691e687ce Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 9 Sep 2016 15:28:37 +0200 Subject: [PATCH 2/4] Added logging to see how long compression took CURA-2286 --- NetworkPrinterOutputDevice.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NetworkPrinterOutputDevice.py b/NetworkPrinterOutputDevice.py index 7bb1eb59d9..c606546e3e 100644 --- a/NetworkPrinterOutputDevice.py +++ b/NetworkPrinterOutputDevice.py @@ -551,7 +551,9 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): if self._use_gzip: file_name = "%s.gcode.gz" % Application.getInstance().getPrintInformation().jobName + compress_time = time() single_string_file_data = gzip.compress(single_string_file_data.encode("utf-8")) + Logger.log("d", "It took %s seconds to compress the file", time() - compress_time) # Pretend that this is a response, as zipping might take a bit of time. self._last_response_time = time() else: From 7f0194cce01d1a50f01b4e95f05ce33d9a59403b Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 9 Sep 2016 15:44:02 +0200 Subject: [PATCH 3/4] We now compress the g-code layer by layer so the GIL won't always lock fully CURA-2286 --- NetworkPrinterOutputDevice.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/NetworkPrinterOutputDevice.py b/NetworkPrinterOutputDevice.py index c606546e3e..d5f74f5787 100644 --- a/NetworkPrinterOutputDevice.py +++ b/NetworkPrinterOutputDevice.py @@ -18,8 +18,10 @@ from PyQt5.QtWidgets import QMessageBox import json import os import gzip +import zlib from time import time +from time import sleep i18n_catalog = i18nCatalog("cura") @@ -544,21 +546,22 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): self._progress_message = Message(i18n_catalog.i18nc("@info:status", "Sending data to printer"), 0, False, -1) self._progress_message.show() Logger.log("d", "Started sending g-code to remote printer.") + ## Mash the data into single string - single_string_file_data = "" + byte_array_file_data = b"" for line in self._gcode: - single_string_file_data += line + if self._use_gzip: + byte_array_file_data += gzip.compress(line.encode("utf-8")) + sleep(0) # Yield. + # Pretend that this is a response, as zipping might take a bit of time. + self._last_response_time = time() + else: + byte_array_file_data += line.encode("utf-8") if self._use_gzip: file_name = "%s.gcode.gz" % Application.getInstance().getPrintInformation().jobName - compress_time = time() - single_string_file_data = gzip.compress(single_string_file_data.encode("utf-8")) - Logger.log("d", "It took %s seconds to compress the file", time() - compress_time) - # Pretend that this is a response, as zipping might take a bit of time. - self._last_response_time = time() else: file_name = "%s.gcode" % Application.getInstance().getPrintInformation().jobName - single_string_file_data = single_string_file_data.encode("utf-8") ## Create multi_part request self._post_multi_part = QHttpMultiPart(QHttpMultiPart.FormDataType) @@ -567,7 +570,7 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): self._post_part = QHttpPart() self._post_part.setHeader(QNetworkRequest.ContentDispositionHeader, "form-data; name=\"file\"; filename=\"%s\"" % file_name) - self._post_part.setBody(single_string_file_data) + self._post_part.setBody(byte_array_file_data) self._post_multi_part.append(self._post_part) url = QUrl("http://" + self._address + self._api_prefix + "print_job") From f294d580a98cf8837bb5770d60e8cd8a37aaef2c Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 9 Sep 2016 16:46:04 +0200 Subject: [PATCH 4/4] Zipping the data no longer causes GUI to freeze CURA-2286 --- NetworkPrinterOutputDevice.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NetworkPrinterOutputDevice.py b/NetworkPrinterOutputDevice.py index d5f74f5787..0624c817d1 100644 --- a/NetworkPrinterOutputDevice.py +++ b/NetworkPrinterOutputDevice.py @@ -11,7 +11,7 @@ from cura.PrinterOutputDevice import PrinterOutputDevice, ConnectionState import cura.Settings.ExtruderManager from PyQt5.QtNetwork import QHttpMultiPart, QHttpPart, QNetworkRequest, QNetworkAccessManager, QNetworkReply -from PyQt5.QtCore import QUrl, QTimer, pyqtSignal, pyqtProperty, pyqtSlot +from PyQt5.QtCore import QUrl, QTimer, pyqtSignal, pyqtProperty, pyqtSlot, QCoreApplication from PyQt5.QtGui import QImage from PyQt5.QtWidgets import QMessageBox @@ -552,7 +552,7 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): for line in self._gcode: if self._use_gzip: byte_array_file_data += gzip.compress(line.encode("utf-8")) - sleep(0) # Yield. + QCoreApplication.processEvents() # Ensure that the GUI does not freeze. # Pretend that this is a response, as zipping might take a bit of time. self._last_response_time = time() else: