How to find out if another process is using a file

Donn Cave donn at
Thu Jan 18 21:02:11 CET 2007

In article <mailman.2878.1169141728.32031.python-list at>,
 "Gabriel Genellina" <gagsl-py at> wrote:

> "Tom Wright" <tew24 at> escribió en el mensaje 
> news:eoo6vd$33u$1 at
> > 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.
> Use with the O_EXCL flag; will fail if the other process has the 
> file still open (and will fail if another process is reading the file, too, 
> not just if someone is writing).

O_EXCL fails if the file exists at all - whether closed or open.

   Donn Cave, donn at

More information about the Python-list mailing list