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

Uploaded Python 3

File details

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

File metadata

  • Download URL: philiprehberger_lock_run-0.1.5.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.5.tar.gz
Algorithm Hash digest
SHA256 a6ad22a611865d6f72886307e6fb0353f41de156d52f5ba7e6ceaa468b8bf1d3
MD5 58837d4cf573df4a7b8c3f8184e15f54
BLAKE2b-256 aab7bfd853254f57e451cd7c20c5cedfbc02dae8a96a30ff922e3bf000d755ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_lock_run-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 97e15b0a8d50726deb83c246713f2b83863909828bf95f57fcae325c0d731b1b
MD5 f08866751ef45f29ae987069a84102c9
BLAKE2b-256 2373792aff67e870f316729507996e2eeac809b53461a5ac77262fc352a97804

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