flufl.lock
NFS-safe file locking with timeouts for POSIX and Windows
What it is and what it does
flufl.lock is a file-based locking library that solves the race-condition problem inherent in NFS file systems by using an atomic link-based algorithm inspired by the O_EXCL flag behavior. Instead of relying on exclusive file creation (which is broken on NFS), it creates a unique temporary file and uses the link(2) system call to atomically establish the lock—a technique that works correctly across network file systems and local filesystems alike.
The library is designed for distributed and multi-process environments where you need to coordinate access to shared resources. It supports lock breaking with configurable timeouts, allowing other processes to forcibly acquire a lock if the holder exceeds its declared lifetime. This prevents permanent deadlocks but requires careful tuning: set the lifetime too long and processes will hang waiting; too short and you risk trampling on active locks and corrupting data. It runs on POSIX systems (Linux, macOS) and Windows, making it suitable for cross-platform applications that must coordinate file access.
Use it for:
- Serialize access to shared configuration or data files in a distributed system where multiple hosts mount the same NFS volume.
- Prevent concurrent writes to a shared database or log file in a multi-process web application or job queue.
- Implement a distributed task lock so only one worker process executes a critical operation across a cluster.
- Protect against race conditions in CI/CD pipelines or build systems that run on shared network storage.
- Coordinate resource access in containerized or Kubernetes environments where pods may share persistent volumes.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides NFS-safe file locking with timeout support across POSIX and Windows systems, using an atomic link-based algorithm to prevent race conditions.
Yes. This is a mature, actively maintained library with no known vulnerabilities, low install friction, and a permissive license. Install it if you need cross-platform, NFS-safe file locking with timeout support. The main consideration is tuning the lock lifetime correctly for your use case; if you're unsure whether you need NFS safety specifically, a simpler locking mechanism may suffice.
Install
flufl-lock on PyPI
pip
pip install flufl-lockuv
uv add flufl-lockpoetry
poetry add flufl-lockInstalling flufl.lock
Before you install
Low friction installation with only two lightweight runtime dependencies (atpublic, psutil). Actively maintained with a recent release; marked Production/Stable and Mature.
License in practice
Apache-2.0 is permissive; you can use this in commercial and proprietary projects with minimal restrictions beyond attribution and liability disclaimers.
Quickstart
from flufl.lock import Lock
lock = Lock('/tmp/mylock')
with lock:
# critical section
pass
Requires Python 3.10 or later; lock lifetime must be chosen carefully to balance between process hangs and data corruption risk.
Verify before relying
- Whether clock synchronization requirements are critical in practice for typical use cases outside distributed NFS environments.
- Performance characteristics under high contention or with very short lock lifetimes.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — atpublic, psutil |
| Maintenance | actively maintained — 109 days since the last release |
| First released | |
| Downloads | 3,168,832/month — #2,718 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: flufl_lock-9.1.0-py3-none-any.whl
Keywords: lock, locking, locks
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
zc.lockfileProvides portable inter-process locks…
unclear · top 5,000 on PyPI
portalockerPortalocker provides cross-platform file…
permissive · top 1,000 on PyPI
lockfileProvides a platform-independent file locking…
permissive · top 1,000 on PyPI
filelockProvides a platform-independent file locking…
permissive · top 100 on PyPI
locketLocket provides file-based locks for…
permissive · top 1,000 on PyPI
redlockImplements the RedLock algorithm to provide…
permissive · top 15,000 on PyPI
fastenersProvides cross-platform locks for synchronizing…
permissive · top 5,000 on PyPI
flufl.bounceDetects and extracts original bouncing email…
permissive · top 15,000 on PyPI
oslo.concurrencyoslo.concurrency provides locking mechanisms…
permissive · top 15,000 on PyPI
aiorwlockProvides read-write locks for asyncio programs,…
permissive · top 5,000 on PyPI