Skip to main content

Ensure single instance of a command without leaving stale lock files.

Project description

A wrapper command to provide an advisory lock, without leaving stale lock files. Usage: single.py [options] -c command args..

Options:
-h, --help

show this help message and exit

-f LOCK_FILE, --lock-file=LOCK_FILE

Path to the lock file. Default is provided based on the command path if omitted.

-s, --status

Check to see if the file is locked, and if so, by which process. Exit status is 0 if unlocked, 1 if locked.

flock(2)’ed file is used to provide locking. This will not leave stale lock files around. Note that the existance of lock file does not mean that there is an outstanding lock; exclusive flock must be held by a process. So use ‘single.py –status -f /tmp/foo.lock’ to see if the lock is held.

The OS releases the lock upon process termination, so the lock file is released regardless of how the job terminated.

Invocations:

  • single.py -c long-running-scrit arg1 arg2 will ensure only one long-running-scrit will run at a time. Default lock file, specific to the command, is used in the absence of -f option.

  • Lockfile can be explicitely specified as: single.py -f /tmp/lrs-foo.lock -c long-running-scrit foo Two jobs using the same command could be run concurrently by using different lock files, like: single.py -f /tmp/lrs-bar.lock -c long-running-scrit bar

  • Use –status (-s) option to check if a command or a file is locked: single.py -s -f /tmp/foo.lock single.py -s -c long-running-scrit

Example: $ single.py -c sleep 3 & for x in {0..6}; do single.py -s -c sleep; sleep 1; done [1] 32567 locked by 32567: /tmp/single.py_bin_sleep.flock locked by 32567: /tmp/single.py_bin_sleep.flock locked by 32567: /tmp/single.py_bin_sleep.flock [1]+ Done single.py sleep 5 not locked: /tmp/single.py_bin_sleep.flock not locked: /tmp/single.py_bin_sleep.flock

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

single-0.0.2.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file single-0.0.2.tar.gz.

File metadata

  • Download URL: single-0.0.2.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for single-0.0.2.tar.gz
Algorithm Hash digest
SHA256 ea85a085f3aed1ab77ee2f547afe7b3e4eb46a48201b9c13410a1d117b735e86
MD5 50237a6db8c29d4f0173972cae5e98f6
BLAKE2b-256 a05f5478c5c4877e49588a37c90376b9076c1ec59cb4d21e3a55e568b2517b55

See more details on using hashes here.

Supported by

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