Skip to main content

Single-execution lock decorator with Redis and file-based backends.

Project description

Onloq

Lightweight worker concurrency control via redis or file locks.

When multiple workers run the same task simultaneously, Onloq ensures only one proceeds — the rest skip silently. Supports TTL-based expiry, decorator and direct-call usage, and custom error handling.


Install

pip install onloq

Quick Start

from onloq import Onloq

loq = Onloq()  # uses filesystem locks by default

@loq
def my_task():
    ...
# Redis-backed
import redis
loq = Onloq(redis_connection=redis.Redis())

Usage

Decorator

@loq
def send_report():
    ...

@loq(name="custom.lock.name", ttl=60)
def sync_data():
    ...

Direct call

loq.execute(send_report, ttl=30)

Options

Parameter Default Description
redis_connection None Redis client instance. Falls back to file locks if not set.
locks_dir tempdir/onloq_locks Directory for file-based lock files.
ttl 25 Lock lifetime in seconds.
on_error 'raise' Error behavior: 'raise', None (log and suppress), or a callable (name, exc, *args, **kwargs).
logger None Standard logger for warnings and errors.

Behavior

  • If the lock is already held, the call returns None immediately — no waiting, no retry.
  • File locks use mtime to enforce TTL, preventing stale locks from blocking indefinitely.
  • Redis locks use atomic Lua scripts to ensure safe release by the original owner only.
  • Lock names default to module.qualname of the wrapped function.

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

onloq-0.1.3.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

onloq-0.1.3-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file onloq-0.1.3.tar.gz.

File metadata

  • Download URL: onloq-0.1.3.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for onloq-0.1.3.tar.gz
Algorithm Hash digest
SHA256 632cb18c62cac5aa8b6c4376f95493158b98181213aaae47cf1de7048e3deca5
MD5 9f9a8b1464498192edf0e0182fe238bb
BLAKE2b-256 02f56dd89fe9e70f63b721d02efdaf1a0c9e8e6e175b55af72d009d1ee4f74e3

See more details on using hashes here.

File details

Details for the file onloq-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: onloq-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for onloq-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4fdddfde59aa692b238ab290bb80d3a47c0d873be3d99e0da40a3b773c440172
MD5 3affd1af994f18992f2c6f7cee2bc75b
BLAKE2b-256 ab175e2cce0b625001cf6a0a461d68190a48dae262ad8dc9b9a4e3beb4cc7a81

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