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
Metadata
Release files for LockFileSemaphore 3.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| lockfilesemaphore-3.0.2.tar.gz | 3.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lockfilesemaphore-3.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.8 kB
Release files / lockfilesemaphore-3.0.2.tar.gz
| Download URL | lockfilesemaphore-3.0.2.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
81900a030129bc4ec1bf73859497c998c6ab08e15600219e18dc43bb91ba6fb6
|
|
BLAKE2b-256 checksum How to use checksums |
103740c0187fffaf1b3269b4c87ca88b9c52ab4dd7db4dd38ac78103432cf1bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.7
|
Release files / lockfilesemaphore-3.0.2-py3-none-any.whl
| Download URL | lockfilesemaphore-3.0.2-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
972f31e2aa18d44835f0f839f34649b3f769a30dd5a61064599b59572c410732
|
|
BLAKE2b-256 checksum How to use checksums |
15cc856d2ca2bb84e533483caab003a226aa8fad9158a8b792f4f9636e4ec0a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.7
|