Robust file-based semaphore with stale lock recovery and context manager support.
Project description
LockFileSemaphore
A production-grade file-based semaphore to control concurrent access to shared resources across multiple processes or machines.
Includes atomic lock creation, stale lock recovery, timeout handling, and context manager support.
Installation
pip install LockFileSemaphore
Example Usage
Traditional style:
from LockFileSemaphore import begin_semaphore_ops, end_semaphore_ops
lock_id = begin_semaphore_ops("/tmp/resource.lock") #put path to lock file here , may be arbitrary
try:
# Critical section
pass
finally:
end_semaphore_ops("/tmp/resource.lock", lock_id)
Context Manager style:
from LockFileSemaphore import FileLock
with FileLock("/tmp/resource.lock"): #put path to lock file here, may be arbitrary
# Critical section
pass
Features
- Atomic file lock creation (O_CREAT | O_EXCL)
- Stale lock detection and automatic cleanup
- Timeout and retry interval configuration
- Context manager support
- Cross-platform compatibility
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lockfilesemaphore-3.0.2.tar.gz.
File metadata
- Download URL: lockfilesemaphore-3.0.2.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81900a030129bc4ec1bf73859497c998c6ab08e15600219e18dc43bb91ba6fb6
|
|
| MD5 |
aad555a12d37317ce94beedb179980e1
|
|
| BLAKE2b-256 |
103740c0187fffaf1b3269b4c87ca88b9c52ab4dd7db4dd38ac78103432cf1bf
|
File details
Details for the file lockfilesemaphore-3.0.2-py3-none-any.whl.
File metadata
- Download URL: lockfilesemaphore-3.0.2-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
972f31e2aa18d44835f0f839f34649b3f769a30dd5a61064599b59572c410732
|
|
| MD5 |
a5ab105527e776d77cb3533af2b4e710
|
|
| BLAKE2b-256 |
15cc856d2ca2bb84e533483caab003a226aa8fad9158a8b792f4f9636e4ec0a9
|