Jul-03-2020, 10:00 AM
(This post was last modified: Jul-03-2020, 10:01 AM by Gribouillis.)
I don't know why you have this error but the approach of opening the same file again and again at a high frequency while another program now and then modifies the file seems fundamentally wrong to me.
I just want to suggest 3 alternative approaches
I just want to suggest 3 alternative approaches
- You could use the watchdog module available in pypi. Simply create an observer that watches the directory containing file.txt and does something every time the file is modified. I think this is the best strategy because you are reusing a robust code that was specially designed for this use case.
- You could also check the modification time of the file before opening it, thus avoiding many file openings.
- You could add a small sleep() operation in the loop to lower the frequency of your system calls.