A simple file-based lock utility for Python applications
Project description
locktools
A file-based lock utility for Python applications and services. Useful for coordinating access to shared resources, pausing/resuming processes, and ensuring data consistency between distributed components.
Features
- JSON lock file with status, timestamp, service, flush status, and unique lock ID
- Acquire and release locks
- Update and monitor flush status
- Wait for flush completion with timeout
- Read lock file status as a dictionary
Installation
pip install locktools
Usage
from locktools import LockFile
# Create a lock file for the 'dumper' service
lock = LockFile(lockfile_path='.lock', service='dumper', timeout=10)
lock.acquire() # Acquire the lock
# Check if locked
if lock.is_locked():
print("Locked!")
# Update flush status (e.g., after consumer flushes data)
lock.update_flush_status('done')
# Wait for flush status to become 'done' (returns True if successful within timeout)
lock.wait_for_flush(expected_status='done')
# Read lock file status
status = lock.read_status()
print(status)
# Release the lock
lock.release()
Lock File JSON Example
{
"status": "locked",
"timestamp": "2024-06-10T12:34:56.789Z",
"service": "dumper",
"flush_status": "pending",
"lock_id": "uuid-1234-abcd"
}
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
locktools-0.3.1.tar.gz
(4.0 kB
view details)
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 locktools-0.3.1.tar.gz.
File metadata
- Download URL: locktools-0.3.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d84a7a0645f521487ffe79cda867b8144cbd9998d0e6d219183ebbceeb06de1d
|
|
| MD5 |
e7692edecd9d8d9243481a7b184b03ce
|
|
| BLAKE2b-256 |
7c84f8da1a6811eec59aaf799f910eaa5de98beb1d7792e3378108758482287a
|
File details
Details for the file locktools-0.3.1-py3-none-any.whl.
File metadata
- Download URL: locktools-0.3.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c51507256262f66a0d64da561f968ce26ca3ad621cd79ac238098d9f4b171a5
|
|
| MD5 |
3bf00d683b38fb57110a8663c06f0856
|
|
| BLAKE2b-256 |
21f300992b6475e1f40a5537d9467eb6319969fdedfa72bd5333b92edb765d44
|