From 001c1cb009839f85fe7d6a2bdf227a4cad40c0ea Mon Sep 17 00:00:00 2001 From: alfrix Date: Sun, 3 Sep 2023 22:11:28 -0300 Subject: [PATCH] rest: add timeout parameter for system update refresh --- ks_includes/KlippyRest.py | 8 ++++---- panels/system.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ks_includes/KlippyRest.py b/ks_includes/KlippyRest.py index 6dfa31e2..464a082d 100644 --- a/ks_includes/KlippyRest.py +++ b/ks_includes/KlippyRest.py @@ -35,13 +35,13 @@ class KlippyRest: def get_thumbnail_stream(self, thumbnail): return self.send_request(f"server/files/gcodes/{thumbnail}", json=False) - def _do_request(self, method, request_method, data=None, json=None, json_response=True): + def _do_request(self, method, request_method, data=None, json=None, json_response=True, timeout=3): url = f"{self.endpoint}/{method}" headers = {} if self.api_key is False else {"x-api-key": self.api_key} response_data = False try: callee = getattr(requests, request_method) - response = callee(url, json=json, data=data, headers=headers, timeout=3) + response = callee(url, json=json, data=data, headers=headers, timeout=timeout) response.raise_for_status() if json_response: logging.debug(f"Sending request to {url}") @@ -69,8 +69,8 @@ class KlippyRest: def post_request(self, method, data=None, json=None, json_response=True): return self._do_request(method, "post", data, json, json_response) - def send_request(self, method, json=True): - return self._do_request(method, "get", json_response=json) + def send_request(self, method, json=True, timeout=3): + return self._do_request(method, "get", json_response=json, timeout=timeout) @staticmethod def format_status(status): diff --git a/panels/system.py b/panels/system.py index 95a1c0aa..3850994e 100644 --- a/panels/system.py +++ b/panels/system.py @@ -97,7 +97,7 @@ class Panel(ScreenPanel): GLib.timeout_add_seconds(1, self.get_updates, "true") def get_updates(self, refresh="false"): - update_resp = self._screen.apiclient.send_request(f"machine/update/status?refresh={refresh}") + update_resp = self._screen.apiclient.send_request(f"machine/update/status?refresh={refresh}", timeout=60) if not update_resp: self.update_status = {} logging.info("No update manager configured")