Skip to main content

Prevent duplicate script execution using file-based locking

Project description

philiprehberger-lock-run

Tests PyPI version License

Prevent duplicate script execution using file-based locking.

Installation

pip install philiprehberger-lock-run

Usage

Context Manager

from philiprehberger_lock_run import lock

with lock("my-job"):
    do_work()

Decorator

from philiprehberger_lock_run import locked

@locked("my-job")
def scheduled_task():
    ...

Timeout

Wait up to 10 seconds for the lock to become available:

with lock("my-job", timeout=10):
    do_work()

Custom Lock Directory

with lock("my-job", lock_dir="/var/lock"):
    do_work()

API

Name Description
lock(name, *, timeout=0, lock_dir=None) Context manager that acquires a file lock. Raises LockError on failure.
locked(name, **kwargs) Decorator that wraps the function body in a file lock.
LockError Raised when a lock cannot be acquired. Extends RuntimeError.

Development

pip install -e .
python -m pytest tests/ -v

License

MIT

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

philiprehberger_lock_run-0.1.4.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

philiprehberger_lock_run-0.1.4-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_lock_run-0.1.4.tar.gz.

File metadata

  • Download URL: philiprehberger_lock_run-0.1.4.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for philiprehberger_lock_run-0.1.4.tar.gz
Algorithm Hash digest
SHA256 f93213b0037e1c4ceed00bd7d633cccb6f73d7d6a1fbee094e0011faa8ecadec
MD5 d6d675ec08d411dd0d35afaccdbf6ec2
BLAKE2b-256 d807f169ef16dc8754323b30fa4052e9fb8172a4aead5f87f16b810f9fcfc60f

See more details on using hashes here.

File details

Details for the file philiprehberger_lock_run-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_lock_run-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b39decff58f49c972a13ff031ba69eb72bd693e12b3312ad804a9baa7113c575
MD5 9848b5016046f4f25f608ec063354d83
BLAKE2b-256 c31f34da7c202f37c5b9dffb401600a5a52794cec094193d9d6036fd41375170

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