Skip to main content

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.

Author

flufl.lock is Copyright (C) 2007-2020 Barry Warsaw <barry@python.org>

Project details

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flufl.lock-4.0.tar.gz (23.6 kB view details)

Uploaded Source

File details

Details for the file flufl.lock-4.0.tar.gz.

File metadata

  • Download URL: flufl.lock-4.0.tar.gz
  • Upload date:
  • Size: 23.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for flufl.lock-4.0.tar.gz
Algorithm Hash digest
SHA256 b853612c74967d285b6e2f441e0793635ff834e3a8425944777ca8ea7f20a914
MD5 fbf095de1b5104ff96329d72bc4f4bf1
BLAKE2b-256 758aee2735b3cc6d318e1bcbf6b7895fced832894ae37e7562450d9f7d50dc83

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page