Skip to main content

flufl.lock

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) 2004-2026 Barry Warsaw <barry@python.org>

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

Project details

Metadata

Release files for flufl.lock 10.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flufl.lock 10.0.0
File Size Uploaded
flufl_lock-10.0.0.tar.gz 38.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flufl.lock 10.0.0
File Interpreter ABI Platform
flufl_lock-10.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 50.0 kB

Release files / flufl_lock-10.0.0.tar.gz

Download URL flufl_lock-10.0.0.tar.gz
Size 38.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4c425ced02827b03ee09a224ac292dde38451e05ec5bf6ddc93c5aa5d55a4267
BLAKE2b-256 checksum
How to use checksums
b5150abc3a1c66d12adf75a613780d1230a93606215be6880fec491353244a65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / flufl_lock-10.0.0-py3-none-any.whl

Download URL flufl_lock-10.0.0-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
96356d68c2beacd5d22b1fd3ec18704539265d6c0e529bb79ab050c5c66d67ba
BLAKE2b-256 checksum
How to use checksums
48a8584f8ee76d4bc0261b9bdd0d9c902c5a69ce68f741cc91f15a9a1aee7a7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

10.0.0 This release

2 release files

9.2.0

2 release files

9.1.0

2 release files

9.0.0

2 release files

8.2.0

2 release files

8.1.0

2 release files

8.0.2

2 release files

8.0.1

2 release files

8.0

2 release files

7.1.1

2 release files

7.1

2 release files

7.0

2 release files

6.0

1 release file

5.1

1 release file

5.0.5

1 release file

5.0.4

1 release file

5.0.3

1 release file

5.0.2

1 release file

5.0.1

1 release file

5.0

1 release file

4.0

1 release file

3.2

1 release file

3.1

1 release file

3.0

1 release file

2.4.1

1 release file

2.4

1 release file

2.3.1

1 release file

2.3

1 release file

2.2.1

1 release file

2.2

1 release file

2.1.1

1 release file

2.1

1 release file

2.0.2

1 release file

2.0.1

1 release file

2.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page