Skip to main content

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).

Metadata

Release files for pidlock 3.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pidlock 3.0.2
File Size Uploaded
pidlock-3.0.2.linux-x86_64.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pidlock 3.0.2
File Interpreter ABI Platform
pidlock-3.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 12.7 kB

Release files / pidlock-3.0.2.linux-x86_64.tar.gz

Download URL pidlock-3.0.2.linux-x86_64.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5748623848d4f4356b1813fde75d64b9e014905f2a0ca6ed3ed15675969c16a3
BLAKE2b-256 checksum
How to use checksums
a80876f1259d62e624efff55ad3f6ce09080fc0a5f3bea4af3ed2c6059b97e2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release files / pidlock-3.0.2-py3-none-any.whl

Download URL pidlock-3.0.2-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
33cb0706ebb32c7acc68695f57265f25e40d13f14509295b0726f5a12f9c9d76
BLAKE2b-256 checksum
How to use checksums
cf48ee95c33609b9de8233f9364545ab0e45b4f5f3564a3faa6efe147066aaf2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release history Release notifications | RSS feed

This release

3.0.2 This release

2 release files

3.0.1

1 release file

3.0.0

1 release file

2.0.0

1 release file

1.1.5

1 release file

1.1.4

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page