Python thread waiting for copying the file
Question: I have a c program which is running in thread and appending some data in a
file. I want to run a python thread which will copy the same file(which c
thread is writing) after some time interval. Is there any safe way to do this?
I am doing this in linux OS.


Answer: There are a lot of important details to your scenario that aren't mentioned,
but working on the assumption that you can't write a locking mechanism in to
the C program and then use it in the Python program (for example, you're using
an existing application on your system), you could look in to os.stat and
check the last modified time, m_time. That is of course reliant on you knowing
that a recent m_time means the file won't be opened again in the C program and
used again.

If the file handle is kept open in the C program at all times, and written to
occasionally then there is a not a lot of easy options for knowing when it is
and isn't being written to.

