Added retry handler for watch

This commit is contained in:
Eric Renfro 2024-11-26 15:18:59 -05:00
parent 97895234ff
commit 565337975d
Signed by: psi-jack
SSH key fingerprint: SHA256:1TKB8Z257L8EHK8GWNxKgMhD8a+FAR+f+j3nnlcuNVM

View file

@ -109,6 +109,11 @@ def watch():
] ]
found_interface = False found_interface = False
tries = 0
while tries < 5 and found_interface == False:
tries += 1
logging.info("Initializing D-Bus session interface monitor...")
for interface, path in interfaces_to_monitor: for interface, path in interfaces_to_monitor:
try: try:
proxy = session_bus.get_object(interface, path) proxy = session_bus.get_object(interface, path)
@ -121,14 +126,24 @@ def watch():
) )
logging.info(f"Subscribed to {interface} at {path}") logging.info(f"Subscribed to {interface} at {path}")
found_interface = True found_interface = True
break
except KeyboardInterrupt:
print("Exiting by user interupt.")
sys.exit(0)
except dbus.exceptions.DBusException as e: except dbus.exceptions.DBusException as e:
pass pass
#logging.warning(f"Could not subscribe to {interface} at {path}: {e}") #logging.warning(f"Could not subscribe to {interface} at {path}: {e}")
if not found_interface: if not found_interface:
if tries < 5:
try:
time.sleep(5)
except KeyboardInterrupt:
print("Exiting by user interupt.")
sys.exit(0)
else:
logging.error("No suitable interfaces were found. Exiting...") logging.error("No suitable interfaces were found. Exiting...")
return sys.exit(2)
# Start the process monitoring thread # Start the process monitoring thread
monitor_thread = threading.Thread(target=monitor_process, args=(process_name,)) monitor_thread = threading.Thread(target=monitor_process, args=(process_name,))