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.2.1.tar.gz (4.1 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.2.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for locktools-0.2.1.tar.gz
Algorithm Hash digest
SHA256 b32ea3c8ac0c8e7dfc51c42da6b699b3040749e34814fff05e6df158f635b771
MD5 fa6fc6283f29e7596fbd1cb74c012b37
BLAKE2b-256 3197218e53f189534b6f19ad5f73295d7577ce5c136d05b024da54c28c0c3f32

See more details on using hashes here.

File details

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

File metadata

  • Download URL: locktools-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.0 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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a974f4ad0d24297fc73c9aa1219f93e54ab25e91c3fdf2e5323b7ac5f9eeda60
MD5 0831d9cee629a9a52afba268ce666978
BLAKE2b-256 69450bfe46981a1c64b78862c027bb49f764ec51de011ddd58b6649b8d13d611

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