Skip to main content

Simple PID based locking for cronjobs, UNIX scripts or python programs

Project description

pidlock

PyPI version CircleCI

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pidlock-3.0.1.tar.gz (5.9 kB view details)

Uploaded Source

File details

Details for the file pidlock-3.0.1.tar.gz.

File metadata

  • Download URL: pidlock-3.0.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.0+

File hashes

Hashes for pidlock-3.0.1.tar.gz
Algorithm Hash digest
SHA256 583c3de4d205cbc5496d856cb55559df71824b30359921fe7d2ea7725b9a7c4b
MD5 5b3f72040afb28abd24289169b869248
BLAKE2b-256 d4ddc7ee495a79617b415f56d95a0acb03a1dcf3a660734e354c5317c1778b50

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page