Simple PID based locking for cronjobs, UNIX scripts or python programs
Project description
[![PyPI version](https://img.shields.io/pypi/v/pidlock.svg)](https://pypi-hypernode.com/pypi/pidlock)
[![Build Status](https://travis-ci.org/sayanarijit/pidlock.svg?branch=master)](https://travis-ci.org/sayanarijit/pidlock)
# pidlock
Simple PID based locking for cronjobs, UNIX scripts or python programs
### Requirement:
* requires python (>2 or 3)
### 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
```
[![Build Status](https://travis-ci.org/sayanarijit/pidlock.svg?branch=master)](https://travis-ci.org/sayanarijit/pidlock)
# pidlock
Simple PID based locking for cronjobs, UNIX scripts or python programs
### Requirement:
* requires python (>2 or 3)
### 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
```
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
pidlock-2.0.0.tar.gz
(4.7 kB
view details)
File details
Details for the file pidlock-2.0.0.tar.gz
.
File metadata
- Download URL: pidlock-2.0.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7419cbf9d36b62d23bb49e8b81f877b89c53dae5534b8dbb731415052d7d90d7 |
|
MD5 | 445ff368d98e4f1a235561ca8c63842e |
|
BLAKE2b-256 | 4ac3518a73dd14b4c7f497c454e901a3ba406924dedea0703fec1fc657894581 |