filelock
filelock copied to clipboard
filelock expiration
To avoid the case where lock files accidentally get left and lock things forever, we could have the process that acquires the lock set an expiration time on the lock. and if it's expired, the other process can assume that the process died or something and delete and re-acquire the lock.
I guess you can achieve it by yourself. For example, you can write a code: if waiting more than 1 hour, just delete the lock file, and retry to acquire the lock.
Hello, if you make a PR for this (with tests) we would be happy to review it, thanks!
I am interested in this feature and was wondering how to implement it myself. Is there a recognized method for checking the lock file modification time and then removing it without the danger of race conditions?
Not that I'm aware of, you'd likely have to do the research and then implement it 😂
I was afraid of that. So far, I have not been successful in my investigations and I don't have any expertise in Posix filesystem arcana. In fact, it was Googling this topic that led me to your module.
Perhaps a new PIDLock
could be defined that saves the pid of the lock.
If the lock is held by a pid that no longer exists, the the lock is destroyed.
The trick is doing this in a race-condition free manner.
Perhaps this is a starting point? https://stackoverflow.com/questions/17708885/flock-removing-locked-file-without-race-condition