From 236afaf29990ff0ebcccd0a9e47c5377f2c7b675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Leborne?= Date: Wed, 10 Aug 2022 14:53:22 +0200 Subject: [PATCH 1/2] Improve time management when retrieving services metadata --- pyluos/services/service.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/pyluos/services/service.py b/pyluos/services/service.py index 4155051..d2f2399 100644 --- a/pyluos/services/service.py +++ b/pyluos/services/service.py @@ -84,20 +84,35 @@ def _push_data(self, key, new_val, data): @property def firmware_revision(self): + self._firmware_revision = None self._push_value('revision', "") - time.sleep(0.03) + + tick_start = time.time() + while time.time() - tick_start < 1 and self._firmware_revision is None: + time.sleep(0.01) + return self._firmware_revision @property def luos_revision(self): + self._luos_revision = None self._push_value('luos_revision', "") - time.sleep(0.03) + + tick_start = time.time() + while time.time() - tick_start < 1 and self._luos_revision is None: + time.sleep(0.01) + return self._luos_revision @property def uuid(self): + self._uuid = None self._push_value('uuid', "") - time.sleep(0.03) + + tick_start = time.time() + while time.time() - tick_start < 1 and self._uuid is None: + time.sleep(0.01) + return self._uuid @property From 4110a0a7eaa519c27c686be15b78df9bc45fcdde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Leborne?= Date: Fri, 12 Aug 2022 12:58:18 +0200 Subject: [PATCH 2/2] Parameterize metadata read timeout --- pyluos/services/service.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pyluos/services/service.py b/pyluos/services/service.py index d2f2399..2d48094 100644 --- a/pyluos/services/service.py +++ b/pyluos/services/service.py @@ -19,6 +19,7 @@ def widgets(*args, **kwargs): Event = namedtuple('Event', ('name', 'old_value', 'new_value')) +READ_TIMEOUT = 0.3 class Service(object): possible_events = set() @@ -88,7 +89,7 @@ def firmware_revision(self): self._push_value('revision', "") tick_start = time.time() - while time.time() - tick_start < 1 and self._firmware_revision is None: + while time.time() - tick_start < READ_TIMEOUT and self._firmware_revision is None: time.sleep(0.01) return self._firmware_revision @@ -99,7 +100,7 @@ def luos_revision(self): self._push_value('luos_revision', "") tick_start = time.time() - while time.time() - tick_start < 1 and self._luos_revision is None: + while time.time() - tick_start < READ_TIMEOUT and self._luos_revision is None: time.sleep(0.01) return self._luos_revision @@ -110,7 +111,7 @@ def uuid(self): self._push_value('uuid', "") tick_start = time.time() - while time.time() - tick_start < 1 and self._uuid is None: + while time.time() - tick_start < READ_TIMEOUT and self._uuid is None: time.sleep(0.01) return self._uuid