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.1.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.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: philiprehberger_lock_run-0.1.1.tar.gz
  • Upload date:
  • Size: 4.8 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.1.tar.gz
Algorithm Hash digest
SHA256 a9ccd71bdc368baaa2ce8eb2c646646c0405fc7d4a6592342e652d9c055c282c
MD5 b744faa0ef0a6c3c117c1ad1ecc8265a
BLAKE2b-256 97e9b08d1267549d1ce1926147bf459f2d969769326ea62961b6bdac86c02b69

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_lock_run-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d1a647b6af201ce73af89d45b3a4571bb416687ebd07333afe29eb3a0e37027b
MD5 85c61bad46607fa144099508ddc70ff5
BLAKE2b-256 315ac9a62989381827f596917c41cbe1f14c37d4189845a8f676fffdf37f4f79

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