Lock files in case of errors
Hi and thank you so much for creating this awesome library 😃
For my application it's crucial that the lock is eventually released even if the process crashes, so I have some questions that I didn't find answered in the docs:
- How does
filelockmake sure that the lock file is removed even if the app crashes? Is that mechanism reliable or can it fail? - Is there a way to detect "orphan" lock files? Let's say I try to acquire a lock, but the lock already exists. Is there a way to know for how long the lock exists already and break it, let's say if it's older than 1 minute?
Maybe this information would be useful in the docs as well.
I really appreciate your help 🙇
We don't have any good solution for point number one. Similarly, there's nothing built-in for point number two. However, you could try to use the pathlib library to check for the age of the lock file, I guess.
Thanks for the reply @gaborbernat.
I thought about this a bit and indeed ended up with checking the age of the lock file. I was wondering if that wouldn't make a great feature for your library.
Something like that:
lock = FileLock(lock_path, break_after_seconds=20)
This would break an existing lock if it's older than 20 seconds and subsequently acquire it itself.
What do you think?
I think that would be acceptable, but the feature would need to be off by default 🤔