Cross-platform file locking, with Redis, PID-file and bounded-semaphore locks
Actively maintained. Last release 5 weeks ago, commits in 14 of the last 26 weeks. A safe choice.
pip install portalockerCoordinate access. Keep your code simple.
Portalocker provides file locks for Python on Linux, macOS and Windows. Use a context manager to coordinate access between processes, a semaphore to limit concurrent workers, or a Redis lock to coordinate across machines. Python 3.10 or later is required.
Get started | Choose a lock | API reference | Changelog
Install
python -m pip install portalocker
Exclusive file locks work without extra dependencies. Install the optional extra for Redis locks, or for shared file locks on Windows: