How to find out if another process is using a file

js ebgssth at gmail.com
Thu Jan 18 11:43:51 EST 2007


How about using lock?
Let writing process locks the files before writing, and unlock after
the job's done.

I think it'd work  file in most environment.

On 1/19/07, Tom Wright <tew24 at spam.ac.uk> wrote:
> I'm writing a program which reads a series of data files as they are dumped
> into a directory by another process.  At the moment, it gets sporadic bugs
> when it tries to read files which are only partially written.
>
> I'm looking for a function which will tell me if a file is opened in
> write-mode by another process - if it is, my program will ignore it for now
> and come back to it later.  This needs to work on linux and windows.  Mac
> OS would be a bonus too.  An os-independent solution would be good, but I
> could write os-specific options and have it pick the appropriate one.
>
> Is there any way of doing this? I've drawn a blank with google so far.
>
> A nasty hack would be to use the file modification time, and wait until
> that's a few seconds in the past, but is there a nice solution?
>
>
> --
> I'm at CAMbridge, not SPAMbridge
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list