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

Ferature request: A lock type that works for both threads and processes #93

Open
defnull opened this issue Aug 15, 2022 · 1 comment
Open

Comments

@defnull
Copy link

defnull commented Aug 15, 2022

InterProcessLock silently fails if multiple locks on the same file are created in multiple threads of the same process. All threads can acquire the lock, because their process already owns the lock and fcntl.lockf() returns without error. This is obvious if you know how InterProcessLock is implemented and how file lock work on the OS level, but still may surprise users (including myself) and result in hard to debug and reproduce bugs. For example, most deployment options for web applications allow both thread- and process-based concurrency, or even a combination of both. An app might work in one environment but silently fail in other deployments.

To follow the principle of least surprise, InterProcessLock should also acquire thread-level locks, or come with a very visible warning that it does NOT work as expected in multi-threaded environments. I'd love to see a new lock implementation that combines both lock-types in a save way. This would perhaps also help avoid confusion for developers using this library.

@andersjel
Copy link

andersjel commented Jan 30, 2024

Maybe https://www.gnu.org/software/libc/manual/html_node/Open-File-Description-Locks.html could help if you can find something else for other platforms than Linux.

Or maybe https://manpages.debian.org/bookworm/manpages-dev/flock.2.en.html. The Python docs are a little unclear on how exactly this is wrapped across platforms.

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

No branches or pull requests

2 participants