Skip to main content

A simple file-based lock utility for Python applications

Project description

locktools

A file-based lock utility for Python applications and services. Useful for coordinating access to shared resources, pausing/resuming processes, and ensuring data consistency between distributed components.

Features

  • JSON lock file with status, timestamp, service, flush status, and unique lock ID
  • Acquire and release locks
  • Update and monitor flush status
  • Wait for flush completion with timeout
  • Read lock file status as a dictionary

Installation

pip install locktools

Usage

from locktools import LockFile

# Create a lock file for the 'dumper' service
lock = LockFile(lockfile_path='.lock', service='dumper', timeout=10)
lock.acquire()  # Acquire the lock

# Check if locked
if lock.is_locked():
    print("Locked!")

# Update flush status (e.g., after consumer flushes data)
lock.update_flush_status('done')

# Wait for flush status to become 'done' (returns True if successful within timeout)
lock.wait_for_flush(expected_status='done')

# Read lock file status
status = lock.read_status()
print(status)

# Release the lock
lock.release()

Lock File JSON Example

{
  "status": "locked",
  "timestamp": "2024-06-10T12:34:56.789Z",
  "service": "dumper",
  "flush_status": "pending",
  "lock_id": "uuid-1234-abcd"
}

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

locktools-0.3.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

locktools-0.3.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file locktools-0.3.0.tar.gz.

File metadata

  • Download URL: locktools-0.3.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for locktools-0.3.0.tar.gz
Algorithm Hash digest
SHA256 cc52661827040d21ff99ff3ba657a549e7131b580c0807db02b6c1e4e6aecdf9
MD5 0ac10c0e7f190a83e2d4f31228218e07
BLAKE2b-256 3e5fabce51d8a1faf53a2be3d0d6d279cb051097150f8ce50ff98a8c7cda1cc1

See more details on using hashes here.

File details

Details for the file locktools-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: locktools-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for locktools-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 114a5f682e8c2a6b6a9ca41d9a9db6b53dd29d3f5e321177306b2fb140933096
MD5 6992a09ebaa23addb973e5f1ddaf9a39
BLAKE2b-256 1efdde313c732f21c169139834b4b25278d60e87e05eeef6f1a73ec95c6d5f85

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