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-2023 Barry Warsaw <barry@python.org>

Licensed under the terms of the Apache License Version 2.0. See the LICENSE file for details.

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-8.0.2.tar.gz (34.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flufl_lock-8.0.2-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file flufl_lock-8.0.2.tar.gz.

File metadata

  • Download URL: flufl_lock-8.0.2.tar.gz
  • Upload date:
  • Size: 34.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.8.0 CPython/3.10.12

File hashes

Hashes for flufl_lock-8.0.2.tar.gz
Algorithm Hash digest
SHA256 61c7246b34d6e5544c8a1fa4dae396d10e16ceb23371a31db22e0a2993d01432
MD5 f7da2e78df770f496a7dab0554be5690
BLAKE2b-256 dadea17ec72723eb806c71bdcf04519570cbf9baa2d923b9e15ea1a296f6acbe

See more details on using hashes here.

File details

Details for the file flufl_lock-8.0.2-py3-none-any.whl.

File metadata

  • Download URL: flufl_lock-8.0.2-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.8.0 CPython/3.10.12

File hashes

Hashes for flufl_lock-8.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ca33fb581122d651e4f24775bebed1e58cd1ea85a95a505881902ba050ed170b
MD5 291eb5ba949152a5ce59a3565e1a4371
BLAKE2b-256 a8517180739bb87ad89d708ef283f141563124bd8cd5622843cf6ab10456590f

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