Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
some logic help
#3
(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?
Reply


Messages In This Thread
some logic help - by droidus - Jun-10-2023, 05:34 PM
RE: some logic help - by deanhystad - Jun-10-2023, 08:53 PM
RE: some logic help - by droidus - Jun-10-2023, 11:34 PM
RE: some logic help - by deanhystad - Jun-11-2023, 07:55 AM
RE: some logic help - by Gribouillis - Jun-11-2023, 09:28 AM
RE: some logic help - by droidus - Jun-11-2023, 10:41 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020