NFS-safe file locking with timeouts for POSIX and Windows
Project description
NFS-safe file locking with timeouts for POSIX and Windows.
The flufl.lock library provides an NFS-safe file-based locking algorithm influenced by the GNU/Linux open(2) manpage, under the description of the O_EXCL option.
[…] O_EXCL is broken on NFS file systems, programs which rely on it for performing locking tasks will contain a race condition. The solution for performing atomic file locking using a lockfile is to create a unique file on the same fs (e.g., incorporating hostname and pid), use link(2) to make a link to the lockfile. If link() returns 0, the lock is successful. Otherwise, use stat(2) on the unique file to check if its link count has increased to 2, in which case the lock is also successful.
The assumption made here is that there will be no outside interference, e.g. no agent external to this code will ever link() to the specific lock files used.
Lock objects support lock-breaking so that you can’t wedge a process forever. This is especially helpful in a web environment, but may not be appropriate for all applications.
Locks have a lifetime, which is the maximum length of time the process expects to retain the lock. It is important to pick a good number here because other processes will not break an existing lock until the expected lifetime has expired. Too long and other processes will hang; too short and you’ll end up trampling on existing process locks – and possibly corrupting data. In a distributed (NFS) environment, you also need to make sure that your clocks are properly synchronized.
Project details
Project home: https://gitlab.com/warsaw/flufl.lock
Report bugs at: https://gitlab.com/warsaw/flufl.lock/issues
Code hosting: https://gitlab.com/warsaw/flufl.lock.git
Documentation: https://flufllock.readthedocs.io/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file flufl_lock-8.1.0.tar.gz
.
File metadata
- Download URL: flufl_lock-8.1.0.tar.gz
- Upload date:
- Size: 32.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d88302005692a63d98b60080158faf089be5ecae6969f706409da8276fdce7cb |
|
MD5 | 03489ca6897b84761a610df91a7c2acd |
|
BLAKE2b-256 | a9fa885c58f9716063e2ac099f773d0420f20bb834b19538066a2e0d5b848ba4 |
File details
Details for the file flufl_lock-8.1.0-py3-none-any.whl
.
File metadata
- Download URL: flufl_lock-8.1.0-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a01b2153d1b0cc170a26b1413037debbe94af6a1cd23164b3b2b229f766b164f |
|
MD5 | 10b86a5d2e9aca4ad8714c862e32255e |
|
BLAKE2b-256 | 2036e6b26dc9ace9f4fa30f46b3f69182b6f25c07746e0b71caf3cc3c4d78ed2 |