Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lock files in case of errors #363

Open
alfechner opened this issue Sep 21, 2024 · 3 comments
Open

Lock files in case of errors #363

alfechner opened this issue Sep 21, 2024 · 3 comments

Comments

@alfechner
Copy link

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 filelock make 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 🙇

@gaborbernat
Copy link
Member

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.

@alfechner
Copy link
Author

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?

@gaborbernat
Copy link
Member

I think that would be acceptable, but the feature would need to be off by default 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants