Platform-independent file locking for Python, for coordinating processes
open sourceMITfree
filelock is a Python library from the tox-dev project for locking files across processes on any platform. FileLock picks a native locking backend where one exists and a soft marker file otherwise, with cancellable acquire and self-deadlock detection. It also has SoftFileLock and StrictSoftFileLock for shared filesystems, SoftFileLease for expiring claims with a heartbeat, ReadWriteLock (SQLite-backed, many readers and one writer) and SoftReadWriteLock, and async variants of each.
Problems it solves
- stop two Python processes writing the same file at once
- make sure only one copy of my Python script runs at a time
- coordinate readers and a writer of a shared file between Python processes
Features
- FileLock with native backends and a soft fallback
- cancellable acquire and self-deadlock detection
- soft and strict soft locks for shared filesystems
- expiring leases with a heartbeat
- SQLite-backed reader-writer lock
- async variants
