Skip to main content

Prevent duplicate script execution using file-based locking

Project description

philiprehberger-lock-run

Tests PyPI version Last updated

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

Support

If you find this project useful:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

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.6.tar.gz (6.1 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.6-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_lock_run-0.1.6.tar.gz
Algorithm Hash digest
SHA256 c025829628ea033c168208bc14d7c307cc3b407fdec32fd34eaa644ffb3b8c0e
MD5 0ab3f104467366b8fdcbee41a8182d46
BLAKE2b-256 f8bad1e1459c8d33e8d2f7bb5cfaf3e63f5cad3c859e7db9249f4888ee9e6f48

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_lock_run-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 0f31619f318dc5ccb5a1db30d95b9e7c03e7c925be103eb825412c73cc8e652c
MD5 50a6eb057ce6974bc8576b279fbcec86
BLAKE2b-256 769816b87e7c7e613ce7c1ee84ec43172c8444b20dc81cb3eacef5a29f8b6160

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