skillfed

flufl.lock

NFS-safe file locking with timeouts for POSIX and Windows

flufl-lock v9.1.0 3.2M downloads/30d#2,718 on PyPI
Permissive license Apache-2.0 Active released

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-lock

uv

uv add flufl-lock

poetry

poetry add flufl-lock

Installing 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

Development Status :: 5 - Production/StableDevelopment Status :: 6 - MatureIntended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseOperating System :: MacOS :: MacOS XOperating System :: Microsoft :: WindowsOperating System :: POSIXProgramming Language :: PythonProgramming Language :: Python :: 3Topic :: Software Development :: LibrariesTopic :: Software Development :: Libraries :: Python Modules

Tags

NFS-safe file lockingdistributed file locksatomic file lockingcross-platform lock timeoutPOSIX Windows file lockinglock breaking mechanismrace-condition-free locking
distributed-lockingnfs-safecross-platform

More Libraries packages