The flufl.lock library provides an NFS-safe, file-based locking algorithm for POSIX and Windows systems, heavily influenced by the GNU/Linux open(2) manpage's O_EXCL option. It aims to prevent race conditions on NFS file systems by using atomic file operations with robust timeouts and lock-breaking capabilities. Currently at version 9.0.0, the library is under active development with regular updates and maintenance releases.
pip install flufl.lockVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic lock acquisition and release using both context managers and explicit `lock()`/`unlock()` calls. It also shows how to handle `AlreadyLockedError` and refresh a lock. A temporary file is used for demonstration purposes; in production, you would use a stable, shared file path.
Carefully consider the maximum expected duration of your critical section and set the `lifetime` parameter accordingly. Use `lock.refresh()` to extend the lock's lifetime if operations take longer than anticipated.
Ensure all systems accessing the shared lock file have their clocks synchronized, e.g., using NTP.
Upgrade your Python environment to 3.10 or newer (for flufl.lock 9.x) if you need to use the latest version of the library. Check the changelog for specific version requirements if targeting older flufl.lock releases.
If encountering `DistributionNotFound` issues, particularly with tools that rely on older setuptools mechanisms, consider pinning `flufl.lock < 8.0` or checking the downstream application's compatibility matrix.
Install the package using pip: `pip install flufl-lock`
Increase the timeout duration when instantiating the Lock object or when calling the `lock()` method, or ensure the lock file is not perpetually held by another process or stale: `lock = Lock('mylockfile.lock', default_timeout=timedelta(minutes=5))` or `lock.lock(timeout=timedelta(seconds=60))`Ensure the lock is only acquired once per process or use a `try...except AlreadyLockedError` block if re-acquisition attempts are part of the logic, though typically, a check like `if not lock.is_locked: lock.lock()` is preferred.
Verify that the lock is currently held by the process using `lock.is_locked` before attempting to unlock or refresh it, or ensure `unlock()` is called only when the lock is active: `if lock.is_locked: lock.unlock()`
Upgrade `setuptools` and related packaging tools (`pip install --upgrade setuptools pip`) and consider using `importlib_resources` for metadata if still encountering issues, or downgrade `flufl.lock` to a version known to be compatible with your existing dependency resolver if possible. The root cause is often outdated packaging tools or a clash in how different tools interpret package metadata.
No dependency data recorded yet.