> There is one caveat, however. If a process that has the lock crashes without > releasing the lock, the lock file will stay around and prevent other > processes to acquire it. Then you will have to manually remove it. I > generally prefer a solution where the pid of the locking process is written > to the lock file, so that other processes trying to acquire the lock can find > out if the process is still around and remove the lock file if not. I have > seen such solutions on Unix systems. But I am not sure if this can be done in > a platform independent way without the risk of race conditions. Maybe I have > to find out.
True, luckily my application need not be that accurate. Competition for the lock will be rare. My present solution waits a few minutes for the lock to become available, and if not available after that time takes it forcefully (which lockfile handily provides). Certainly not foolproof, but we can recover merely by re-running, so if I get an error or two each year that is acceptable. -- https://mail.python.org/mailman/listinfo/python-list