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.

Install

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.

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.2.tar.gz (4.8 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.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for philiprehberger_lock_run-0.1.2.tar.gz
Algorithm Hash digest
SHA256 9c96ab7abb0b4d8ba5dbca5f8fe6d9b23bdf76332030a889308dc7b438b76e9d
MD5 c28d8658f6859f702d84d891412d1c9b
BLAKE2b-256 3e2dbd0168ff7d7701e52c849ceff21fb1c58848776046769e021fff3f4e3c05

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_lock_run-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1cde900dec2ce2c2513033fc4f4abf29180fef5feaf7654a3bed8a55011d3af7
MD5 d5284ac790576a191f6e0927a355e6f0
BLAKE2b-256 172aff84120e296ab8eb62436d5119c7e7c2a012003141a6cb1a2c901fc33c2e

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