Putting a lock on file.

Harlin Seritt harlinseritt at yahoo.com
Sun Sep 18 02:58:58 EDT 2005


I have a file that a few different running scripts will need to access.
Most likely this won't be a problem but if it is, what do I need to do
to make sure scripts don't crash because the input file is in use?
Would it be best to run a loop like the following:

flag = 0
while not flag:
    try:
        open(file, 'r').read()
        flag = 1
    except:
        pass

This may seem nice on paper but I hate to run a while for an
indeterminate amount of time. Is there anything else that can be done
that would be better?

Thanks,

Harlin Seritt




More information about the Python-list mailing list