waiting for file lock?

Larry Bates larry.bates at websafe.com
Tue Apr 11 09:58:25 EDT 2006


s99999999s2003 at yahoo.com wrote:
> hi
> i need to go into a directory to grab some files and do some
> processing.
> The thing is, i need to wait till the process that generates the files
> in that directory to finish
> before i can grab the files. eg if file A is being generated and has
> not finished, my python script will not go into the directory.
> how can i check that file A has actually finished?  thanks
> 
I don't know if you have control of the program that is writing the
file.  If you do, change it so that it writes the files with some
temporary name and renames them when it is done.  Since rename is
basically atomic, the file won't show up as a candidate to be
processed until it is actually completed.

Something like:

Process A -> writes files into directory with .tmp extensions.
Process B -> scans directory but never processes anything with
             .tmp extensions
Process A -> renames file.tmp to file when it is finished so
             that process B picks it up on its next scan.


-Larry Bates



More information about the Python-list mailing list