Jun-10-2023, 11:34 PM
(Jun-10-2023, 08:53 PM)deanhystad Wrote: You should take a look at watchdog. https://pypi.org/project/watchdog/
I think your loop is wrong. You don't want to re-read the file. You could open the file once for reading and leave it open.
from time import sleep with open("output.txt", "r") as file: for last_line in file: pass while True: sleep(30) for new_line in file: if 'Driver not connected' in new_line or 'Data stale' in new_line: restart_the_driver
I tried the first solution you provided, and it seems to do the same thing. Here's the last lines from the log file before it checks the file again:
"Jun 10 19:40:44 NUT usbhid-ups[26447]: libusb_get_interrupt: error submitting URB: Device or resource busy
Jun 10 19:40:44 NUT usbhid-ups[26447]: Got disconnected by another driver: Device or resource busy
Jun 10 19:40:44 NUT kernel: [369560.918282] usb 1-1.5: usbfs: process 26447 (usbhid-ups) did not claim interface 0 before use
Jun 10 19:40:44 NUT usbhid-ups[26411]: Signal 15: exiting"
Note: This is normal activity, and is fine. These messages can be safely ignored.
It gets stuck in this cycle where it just keeps re-starting the driver again.
Opening the file as such, will that take into account new log entries that are appended to the file?