From 4364d94423b94a682c7e2299be19d57aa566ddbc Mon Sep 17 00:00:00 2001 From: ChrisTerBeke Date: Wed, 4 Sep 2019 18:54:53 +0200 Subject: [PATCH 1/5] Reduce logging and network activity during print job upload --- .../UM3NetworkPrinting/src/Network/LocalClusterOutputDevice.py | 3 --- plugins/UM3NetworkPrinting/src/Network/SendMaterialJob.py | 2 -- 2 files changed, 5 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/Network/LocalClusterOutputDevice.py b/plugins/UM3NetworkPrinting/src/Network/LocalClusterOutputDevice.py index a5a885a4ed..fd9a9e2f60 100644 --- a/plugins/UM3NetworkPrinting/src/Network/LocalClusterOutputDevice.py +++ b/plugins/UM3NetworkPrinting/src/Network/LocalClusterOutputDevice.py @@ -122,9 +122,6 @@ class LocalClusterOutputDevice(UltimakerNetworkedPrinterOutputDevice): self.writeStarted.emit(self) - # Make sure the printer is aware of all new materials as the new print job might contain one. - self.sendMaterialProfiles() - # Export the scene to the correct file type. job = ExportFileJob(file_handler=file_handler, nodes=nodes, firmware_version=self.firmwareVersion) job.finished.connect(self._onPrintJobCreated) diff --git a/plugins/UM3NetworkPrinting/src/Network/SendMaterialJob.py b/plugins/UM3NetworkPrinting/src/Network/SendMaterialJob.py index 83b88341fb..2ad21d2f29 100644 --- a/plugins/UM3NetworkPrinting/src/Network/SendMaterialJob.py +++ b/plugins/UM3NetworkPrinting/src/Network/SendMaterialJob.py @@ -104,7 +104,6 @@ class SendMaterialJob(Job): parts.append(self.device.createFormPart("name=\"signature_file\"; filename=\"{file_name}\"" .format(file_name = signature_file_name), f.read())) - Logger.log("d", "Syncing material %s with cluster.", material_id) # FIXME: move form posting to API client self.device.postFormWithParts(target = "/cluster-api/v1/materials/", parts = parts, on_finished = self._sendingFinished) @@ -117,7 +116,6 @@ class SendMaterialJob(Job): body = reply.readAll().data().decode('utf8') if "not added" in body: # For some reason the cluster returns a 200 sometimes even when syncing failed. - Logger.log("w", "Error while syncing material: %s", body) return # Inform the user that materials have been synced. This message only shows itself when not already visible. # Because of the guards above it is not shown when syncing failed (which is not always an actual problem). From 06d54f397096771ce3655c62a46f9413a6430369 Mon Sep 17 00:00:00 2001 From: ChrisTerBeke Date: Wed, 4 Sep 2019 19:19:49 +0200 Subject: [PATCH 2/5] Remove network manager re-creation that was causing issues --- cura/PrinterOutput/NetworkedPrinterOutputDevice.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/cura/PrinterOutput/NetworkedPrinterOutputDevice.py b/cura/PrinterOutput/NetworkedPrinterOutputDevice.py index e23341ba8a..392df7bded 100644 --- a/cura/PrinterOutput/NetworkedPrinterOutputDevice.py +++ b/cura/PrinterOutput/NetworkedPrinterOutputDevice.py @@ -35,8 +35,6 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice): def __init__(self, device_id, address: str, properties: Dict[bytes, bytes], connection_type: ConnectionType = ConnectionType.NetworkConnection, parent: QObject = None) -> None: super().__init__(device_id = device_id, connection_type = connection_type, parent = parent) self._manager = None # type: Optional[QNetworkAccessManager] - self._last_manager_create_time = None # type: Optional[float] - self._recreate_network_manager_time = 30 self._timeout_time = 10 # After how many seconds of no response should a timeout occur? self._last_response_time = None # type: Optional[float] @@ -133,12 +131,6 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice): self.setConnectionState(ConnectionState.Closed) - # We need to check if the manager needs to be re-created. If we don't, we get some issues when OSX goes to - # sleep. - if time_since_last_response > self._recreate_network_manager_time: - if self._last_manager_create_time is None or time() - self._last_manager_create_time > self._recreate_network_manager_time: - self._createNetworkManager() - assert(self._manager is not None) elif self._connection_state == ConnectionState.Closed: # Go out of timeout. if self._connection_state_before_timeout is not None: # sanity check, but it should never be None here @@ -317,7 +309,6 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice): self._manager = QNetworkAccessManager() self._manager.finished.connect(self._handleOnFinished) - self._last_manager_create_time = time() self._manager.authenticationRequired.connect(self._onAuthenticationRequired) if self._properties.get(b"temporary", b"false") != b"true": From 210843a7bbf3726d8845ae88074147601413a993 Mon Sep 17 00:00:00 2001 From: ChrisTerBeke Date: Thu, 5 Sep 2019 10:47:15 +0200 Subject: [PATCH 3/5] Improve adding/connecting to output devices --- .../src/Cloud/CloudOutputDeviceManager.py | 10 +++++++--- .../src/Network/LocalClusterOutputDeviceManager.py | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py index 168d209db8..1da099dadc 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py @@ -171,7 +171,11 @@ class CloudOutputDeviceManager: machine.setName(device.name) machine.setMetaDataEntry(self.META_CLUSTER_ID, device.key) machine.setMetaDataEntry("group_name", device.name) - - device.connect() machine.addConfiguredConnectionType(device.connectionType.value) - CuraApplication.getInstance().getOutputDeviceManager().addOutputDevice(device) + + if not device.isConnected(): + device.connect() + + output_device_manager = CuraApplication.getInstance().getOutputDeviceManager() + if device.key not in output_device_manager.getOutputDeviceIds(): + output_device_manager.addOutputDevice(device) diff --git a/plugins/UM3NetworkPrinting/src/Network/LocalClusterOutputDeviceManager.py b/plugins/UM3NetworkPrinting/src/Network/LocalClusterOutputDeviceManager.py index e5ae7b83ac..e55eb12fed 100644 --- a/plugins/UM3NetworkPrinting/src/Network/LocalClusterOutputDeviceManager.py +++ b/plugins/UM3NetworkPrinting/src/Network/LocalClusterOutputDeviceManager.py @@ -236,7 +236,11 @@ class LocalClusterOutputDeviceManager: machine.setName(device.name) machine.setMetaDataEntry(self.META_NETWORK_KEY, device.key) machine.setMetaDataEntry("group_name", device.name) - - device.connect() machine.addConfiguredConnectionType(device.connectionType.value) - CuraApplication.getInstance().getOutputDeviceManager().addOutputDevice(device) + + if not device.isConnected(): + device.connect() + + output_device_manager = CuraApplication.getInstance().getOutputDeviceManager() + if device.key not in output_device_manager.getOutputDeviceIds(): + output_device_manager.addOutputDevice(device) From a04bcbb3e9d7a193a30684cc07a55ad8141f9a0b Mon Sep 17 00:00:00 2001 From: ChrisTerBeke Date: Thu, 5 Sep 2019 11:05:26 +0200 Subject: [PATCH 4/5] Revert "Remove network manager re-creation that was causing issues" This reverts commit 06d54f397096771ce3655c62a46f9413a6430369. --- cura/PrinterOutput/NetworkedPrinterOutputDevice.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cura/PrinterOutput/NetworkedPrinterOutputDevice.py b/cura/PrinterOutput/NetworkedPrinterOutputDevice.py index 392df7bded..e23341ba8a 100644 --- a/cura/PrinterOutput/NetworkedPrinterOutputDevice.py +++ b/cura/PrinterOutput/NetworkedPrinterOutputDevice.py @@ -35,6 +35,8 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice): def __init__(self, device_id, address: str, properties: Dict[bytes, bytes], connection_type: ConnectionType = ConnectionType.NetworkConnection, parent: QObject = None) -> None: super().__init__(device_id = device_id, connection_type = connection_type, parent = parent) self._manager = None # type: Optional[QNetworkAccessManager] + self._last_manager_create_time = None # type: Optional[float] + self._recreate_network_manager_time = 30 self._timeout_time = 10 # After how many seconds of no response should a timeout occur? self._last_response_time = None # type: Optional[float] @@ -131,6 +133,12 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice): self.setConnectionState(ConnectionState.Closed) + # We need to check if the manager needs to be re-created. If we don't, we get some issues when OSX goes to + # sleep. + if time_since_last_response > self._recreate_network_manager_time: + if self._last_manager_create_time is None or time() - self._last_manager_create_time > self._recreate_network_manager_time: + self._createNetworkManager() + assert(self._manager is not None) elif self._connection_state == ConnectionState.Closed: # Go out of timeout. if self._connection_state_before_timeout is not None: # sanity check, but it should never be None here @@ -309,6 +317,7 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice): self._manager = QNetworkAccessManager() self._manager.finished.connect(self._handleOnFinished) + self._last_manager_create_time = time() self._manager.authenticationRequired.connect(self._onAuthenticationRequired) if self._properties.get(b"temporary", b"false") != b"true": From da4fcc8ee6b25a6ecd39d4662f913177cb754883 Mon Sep 17 00:00:00 2001 From: ChrisTerBeke Date: Thu, 5 Sep 2019 14:08:18 +0200 Subject: [PATCH 5/5] Revert "Revert "Remove network manager re-creation that was causing issues"" This reverts commit a04bcbb3e9d7a193a30684cc07a55ad8141f9a0b. --- cura/PrinterOutput/NetworkedPrinterOutputDevice.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/cura/PrinterOutput/NetworkedPrinterOutputDevice.py b/cura/PrinterOutput/NetworkedPrinterOutputDevice.py index e23341ba8a..392df7bded 100644 --- a/cura/PrinterOutput/NetworkedPrinterOutputDevice.py +++ b/cura/PrinterOutput/NetworkedPrinterOutputDevice.py @@ -35,8 +35,6 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice): def __init__(self, device_id, address: str, properties: Dict[bytes, bytes], connection_type: ConnectionType = ConnectionType.NetworkConnection, parent: QObject = None) -> None: super().__init__(device_id = device_id, connection_type = connection_type, parent = parent) self._manager = None # type: Optional[QNetworkAccessManager] - self._last_manager_create_time = None # type: Optional[float] - self._recreate_network_manager_time = 30 self._timeout_time = 10 # After how many seconds of no response should a timeout occur? self._last_response_time = None # type: Optional[float] @@ -133,12 +131,6 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice): self.setConnectionState(ConnectionState.Closed) - # We need to check if the manager needs to be re-created. If we don't, we get some issues when OSX goes to - # sleep. - if time_since_last_response > self._recreate_network_manager_time: - if self._last_manager_create_time is None or time() - self._last_manager_create_time > self._recreate_network_manager_time: - self._createNetworkManager() - assert(self._manager is not None) elif self._connection_state == ConnectionState.Closed: # Go out of timeout. if self._connection_state_before_timeout is not None: # sanity check, but it should never be None here @@ -317,7 +309,6 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice): self._manager = QNetworkAccessManager() self._manager.finished.connect(self._handleOnFinished) - self._last_manager_create_time = time() self._manager.authenticationRequired.connect(self._onAuthenticationRequired) if self._properties.get(b"temporary", b"false") != b"true":