From 93cc25b4081e4a92feff6dc6bbeab2519e2f3560 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Wed, 7 Sep 2016 11:56:19 +0200 Subject: [PATCH] Added exception handling for when wrapped reply object is already deleted CURA-2295 --- NetworkPrinterOutputDevice.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/NetworkPrinterOutputDevice.py b/NetworkPrinterOutputDevice.py index 8ec071cb82..6ab697ed5e 100644 --- a/NetworkPrinterOutputDevice.py +++ b/NetworkPrinterOutputDevice.py @@ -252,13 +252,16 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): self._connection_message.show() # Check if we were uploading something. Abort if this is the case. # Some operating systems handle this themselves, others give weird issues. - if self._post_reply: - self._post_reply.abort() - try: - self._post_reply.uploadProgress.disconnect(self._onUploadProgress) - except TypeError: - pass # The disconnection can fail on mac in some cases. Ignore that. - self._progress_message.hide() + try: + if self._post_reply: + self._post_reply.abort() + try: + self._post_reply.uploadProgress.disconnect(self._onUploadProgress) + except TypeError: + pass # The disconnection can fail on mac in some cases. Ignore that. + self._progress_message.hide() + except RuntimeError: + self._post_reply = None # It can happen that the wrapped c++ object is already deleted. return else: self._recreate_network_manager_count = 1 @@ -273,13 +276,16 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): self._connection_message.show() # Check if we were uploading something. Abort if this is the case. # Some operating systems handle this themselves, others give weird issues. - if self._post_reply: - self._post_reply.abort() - try: - self._post_reply.uploadProgress.disconnect(self._onUploadProgress) - except TypeError: - pass # The disconnection can fail on mac in some cases. Ignore that. - self._progress_message.hide() + try: + if self._post_reply: + self._post_reply.abort() + try: + self._post_reply.uploadProgress.disconnect(self._onUploadProgress) + except TypeError: + pass # The disconnection can fail on mac in some cases. Ignore that. + self._progress_message.hide() + except RuntimeError: + self._post_reply = None # It can happen that the wrapped c++ object is already deleted. self.setConnectionState(ConnectionState.error) return