Simple PID based locking for cronjobs, UNIX scripts or python programs
Project description
pidlock
Simple PID based locking for cronjobs, UNIX scripts or python programs. Copes with locking between hosts.
Requirement
- requires python3
Usage
- Install with pip
sudo pip install -U pidlock
- Use it from inside python script
import time
from pidlock import PIDLock
locker = PIDLock()
with locker.lock('sleepy_script'):
time.sleep(10)
- Use it as commandline/cron job
# To display help menu
pidlock -h # Or pidlock --help
# Example usage
pidlock -n sleepy_script -c 'sleep 10'
# Same as
pidlock --name sleepy_script --command 'sleep 10'
Customization:
- You can pass PID file location, verbosity, time limit and minimum interval as arguments
# Python Usage
locker = PIDLock(lockdir='~/.pidlock', verbose=True)
with locker.lock('sleepy_script', wait=10, mininterval=1):
time.sleep(10)
# Commandline usage
pidlock -n sleepy_script -c 'sleep 10' -l ~/.pidlock -v -w 10 -m 1
# Same as
pidlock --name sleepy_script --command 'sleep 10' --lockdir ~/.pidlock --verbose --wait 10 --mininterval 1
Contributions
Originally written and published by Arijit Basu. Adaptation to cope with race conditions by Keiran Raine (ongoing owner/support).
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
File details
Details for the file pidlock-3.0.2.linux-x86_64.tar.gz
.
File metadata
- Download URL: pidlock-3.0.2.linux-x86_64.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5748623848d4f4356b1813fde75d64b9e014905f2a0ca6ed3ed15675969c16a3 |
|
MD5 | 895a51c59c65351beb5a1d026694e7c4 |
|
BLAKE2b-256 | a80876f1259d62e624efff55ad3f6ce09080fc0a5f3bea4af3ed2c6059b97e2d |
File details
Details for the file pidlock-3.0.2-py3-none-any.whl
.
File metadata
- Download URL: pidlock-3.0.2-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33cb0706ebb32c7acc68695f57265f25e40d13f14509295b0726f5a12f9c9d76 |
|
MD5 | c5b7141f8e4adab2eded4ee664a99454 |
|
BLAKE2b-256 | cf48ee95c33609b9de8233f9364545ab0e45b4f5f3564a3faa6efe147066aaf2 |