From 57b1cb3bc856582ea9e5da1240a8aa47ca0cab59 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Tue, 10 Oct 2017 10:52:00 +0200 Subject: [PATCH] Refactor camera request fix CURA-4376 - Simplify the exception handling - Use isFinished() to check the state of the network request --- .../NetworkPrinterOutputDevice.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py index a389b7d2f9..7683f3d860 100755 --- a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py +++ b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py @@ -332,16 +332,15 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): self._camera_timer.stop() if self._image_reply: - skip_abort = False try: + # disconnect the signal try: self._image_reply.downloadProgress.disconnect(self._onStreamDownloadProgress) - except Exception as e: - if type(e) != RuntimeError: # can happen the RuntimeError occurs before calling abort (=see below), then then the application will crash - skip_abort = True - pass #The signal was never connected. - if not skip_abort: - self._image_reply.abort() + except Exception: + pass + # abort the request if it's not finished + if not self._image_reply.isFinished(): + self._image_reply.close() except Exception as e: #RuntimeError pass # It can happen that the wrapped c++ object is already deleted. self._image_reply = None