From 22b9bb77efb0a0268dc1968b6a9eb41aa0eaf90b Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Fri, 5 Jun 2020 12:59:31 +0200 Subject: [PATCH 1/3] Fix reporting the [WinError 10038] exception traceback on sign-in Surround the serve_forever function of the web server with a try-catch on Windows, in order to avoid printing the entire (useless) traceback. Now a warning message is be displayed in the log instead. The behavior is untouched in other platforms --- cura/OAuth2/LocalAuthorizationServer.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/cura/OAuth2/LocalAuthorizationServer.py b/cura/OAuth2/LocalAuthorizationServer.py index f819042ae0..211b59683f 100644 --- a/cura/OAuth2/LocalAuthorizationServer.py +++ b/cura/OAuth2/LocalAuthorizationServer.py @@ -1,6 +1,6 @@ # Copyright (c) 2020 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. - +import sys import threading from typing import Any, Callable, Optional, TYPE_CHECKING @@ -71,7 +71,7 @@ class LocalAuthorizationServer: self._web_server.setState(state) # Start the server on a new thread. - self._web_server_thread = threading.Thread(None, self._web_server.serve_forever, daemon = self._daemon) + self._web_server_thread = threading.Thread(None, self._serve_forever, daemon = self._daemon) self._web_server_thread.start() def stop(self) -> None: @@ -87,3 +87,20 @@ class LocalAuthorizationServer: pass self._web_server = None self._web_server_thread = None + + def _serve_forever(self) -> None: + """ + If the platform is windows, this function calls the serve_forever function of the _web_server, catching any + OSErrors that may occur in the thread, thus making the reported message more log-friendly. + If it is any other platform, it just calls the serve_forever function immediately. + + :return: None + """ + if sys.platform == "win32": + try: + self._web_server.serve_forever() + except OSError as e: + Logger.warning(str(e)) + else: + # Leave the default behavior in non-windows platforms + self._web_server.serve_forever() From ea6a73e76d4712d7a9371ee9b61d365e190d797a Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Fri, 5 Jun 2020 13:18:48 +0200 Subject: [PATCH 2/3] Fix mypy complains --- cura/OAuth2/LocalAuthorizationServer.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/cura/OAuth2/LocalAuthorizationServer.py b/cura/OAuth2/LocalAuthorizationServer.py index 211b59683f..a41de2d406 100644 --- a/cura/OAuth2/LocalAuthorizationServer.py +++ b/cura/OAuth2/LocalAuthorizationServer.py @@ -96,11 +96,12 @@ class LocalAuthorizationServer: :return: None """ - if sys.platform == "win32": - try: + if self._web_server: + if sys.platform == "win32": + try: + self._web_server.serve_forever() + except OSError as e: + Logger.warning(str(e)) + else: + # Leave the default behavior in non-windows platforms self._web_server.serve_forever() - except OSError as e: - Logger.warning(str(e)) - else: - # Leave the default behavior in non-windows platforms - self._web_server.serve_forever() From 42daef0a7511969950d2c8b417f7e8a49f373809 Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Fri, 5 Jun 2020 13:20:38 +0200 Subject: [PATCH 3/3] Remove spam info message --- .../UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py index 7ee8322ba1..30c26a2c24 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py @@ -91,8 +91,6 @@ class CloudOutputDeviceManager: if self._syncing: return - Logger.info("Syncing cloud printer clusters") - self._syncing = True self._account.setSyncState(self.SYNC_SERVICE_NAME, SyncState.SYNCING) self._api.getClusters(self._onGetRemoteClustersFinished, self._onGetRemoteClusterFailed)