Prevent duplicate script execution using file-based locking
Project description
philiprehberger-lock-run
Prevent duplicate script execution using file-based locking.
Install
pip install philiprehberger-lock-run
Usage
Context Manager
from philiprehberger_lock_run import lock
with lock("my-job"):
do_work()
Decorator
from philiprehberger_lock_run import locked
@locked("my-job")
def scheduled_task():
...
Timeout
Wait up to 10 seconds for the lock to become available:
with lock("my-job", timeout=10):
do_work()
Custom Lock Directory
with lock("my-job", lock_dir="/var/lock"):
do_work()
API
| Name | Description |
|---|---|
lock(name, *, timeout=0, lock_dir=None) |
Context manager that acquires a file lock. Raises LockError on failure. |
locked(name, **kwargs) |
Decorator that wraps the function body in a file lock. |
LockError |
Raised when a lock cannot be acquired. Extends RuntimeError. |
Development
pip install -e .
python -m pytest tests/ -v
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
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 philiprehberger_lock_run-0.1.3.tar.gz.
File metadata
- Download URL: philiprehberger_lock_run-0.1.3.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
159e518627ff9568d2d94b0b1a682313d928acdf367403696641fe917c88fcd1
|
|
| MD5 |
81018f4f787582d79775c978d9e28a20
|
|
| BLAKE2b-256 |
6f9c217695edc1534f71c624a55060d703e60bc06108d1fa4c8991feeda27a6c
|
File details
Details for the file philiprehberger_lock_run-0.1.3-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_lock_run-0.1.3-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14ff9b26dae6e62bfdf7ff24be1aa99bfd5506c22c9ba604b70678a069487dd7
|
|
| MD5 |
ad9d9e0c3f4717ffaedec6c16aa0ee71
|
|
| BLAKE2b-256 |
f9d6f7c745e045918340e5668e18256b79f8ab0274443f0058f878dd4e2d50c8
|