1 year ago

#386178

test-img

Nrmn

How do I make my Python program check and wait for a txt file to be accessible?

Problem
I have third-party software that generates a text file and appends a new line to it after x seconds.

My program reads the data points live from the text file and displays values as a plot in Matplotlib with FuncAnimation. However, sometimes it slows down because the software and Python obviously try to access the text file simultaneously when their timing overlaps.

My Goal
I want the Python code, when started at any point in time, to check if the text file is currently being used and if so, wait until it is not anymore. That means I want it to only try to access the file when it is actually not used by the software.

I appreciate your help! (I do not think it is necessary to present a code example here because this is a more general question and not a specific problem in my code. Of course, I will do so if explicitly wished for!)

python

wait

0 Answers

Your Answer

Accepted video resources