Metadata-Version: 2.4
Name: philiprehberger-lock-run
Version: 0.1.1
Summary: Prevent duplicate script execution using file-based locking
Project-URL: Homepage, https://github.com/philiprehberger/py-lock-run
Project-URL: Repository, https://github.com/philiprehberger/py-lock-run
Project-URL: Issues, https://github.com/philiprehberger/py-lock-run/issues
Author: Philip Rehberger
License-Expression: MIT
License-File: LICENSE
Keywords: concurrency,cron,file-lock,lock,mutex,process-lock
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# philiprehberger-lock-run

[![Tests](https://github.com/philiprehberger/py-lock-run/actions/workflows/publish.yml/badge.svg)](https://github.com/philiprehberger/py-lock-run/actions/workflows/publish.yml)
[![PyPI version](https://img.shields.io/pypi/v/philiprehberger-lock-run.svg)](https://pypi.org/project/philiprehberger-lock-run/)
[![License](https://img.shields.io/github/license/philiprehberger/py-lock-run)](LICENSE)

Prevent duplicate script execution using file-based locking.

## Install

```bash
pip install philiprehberger-lock-run
```

## Usage

### Context Manager

```python
from philiprehberger_lock_run import lock

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

### Decorator

```python
from philiprehberger_lock_run import locked

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

### Timeout

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

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

### Custom Lock Directory

```python
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
