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.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.0.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.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: locktools-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 93e8884d2f88eea2409c3e0e4115678222cf4cc5f01f01eab42d396ff11c8295
MD5 2064730663848938b82a8fd23fc16d3d
BLAKE2b-256 43b8ff6a588d01a36f3f9b35be5dfce6ccb72044f9b91c1713ec4a71c4832169

See more details on using hashes here.

File details

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

File metadata

  • Download URL: locktools-0.2.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 617503e37ff9c2ebfae3be4ecf9b8e09f15ba6706ce572dfb2b28de4d25978fc
MD5 8221f3d5761b905d6da58e194973c388
BLAKE2b-256 cb216371dcf19f3d6231a8adef89cce1d49b3d56f4479c2150556d4b944638a9

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