Bladeren bron

add retries for kwin query

Thomas B 3 maanden geleden
bovenliggende
commit
f0b932ef2f
2 gewijzigde bestanden met toevoegingen van 12 en 2 verwijderingen
  1. 1
    1
      client/lux.py
  2. 11
    1
      client/window.py

+ 1
- 1
client/lux.py Bestand weergeven

@@ -8,7 +8,7 @@ CUSTOM_RQ_ECHO = 0 # send back wValue and wIndex, for testing comms reliability
8 8
 CUSTOM_RQ_RESET = 1 # reset to bootloader
9 9
 CUSTOM_RQ_GET = 2 # get ldr value
10 10
 
11
-max_comm_retries = 5;
11
+max_comm_retries = 5
12 12
 
13 13
 def is_target_device(dev):
14 14
     if dev.manufacturer == "xythobuz.de" and dev.product == "AutoBrightness":

+ 11
- 1
client/window.py Bestand weergeven

@@ -5,8 +5,10 @@ import subprocess
5 5
 from datetime import datetime
6 6
 import json
7 7
 
8
+max_comm_retries = 5
9
+
8 10
 # https://unix.stackexchange.com/a/776620
9
-def query(verbose=False):
11
+def query_internal(verbose=False):
10 12
     dir_path = os.path.abspath(os.path.dirname(__file__))
11 13
     file_path = os.path.join(dir_path, "kwin_check.js")
12 14
     datetime_now = datetime.now()
@@ -44,6 +46,14 @@ def query(verbose=False):
44 46
     msg = result.stdout.decode().rstrip().split("\n")[0][4:]
45 47
     return json.loads(msg)
46 48
 
49
+def query(verbose=False):
50
+    for attempts in range(0, max_comm_retries):
51
+        try:
52
+            return query_internal(verbose)
53
+        except Exception as e:
54
+            if attempts >= (max_comm_retries - 1):
55
+                raise e
56
+
47 57
 if __name__ == "__main__":
48 58
     info = query()
49 59
     print("Name: \"{}\"".format(info["name"]))

Laden…
Annuleren
Opslaan