Skip to main content

A simple directory based lock implementation for Python.

Project description

Dirlock

PyPi badge pytest badge

A simple directory-based lock implementation for Python. This package provides a lightweight and effective way to coordinate access to shared resources using a lock directory mechanism. This does not require any file locking capabilities of the underlying filesystem or network share.

Installation

Install the package via pip:

pip install dirlock

Usage

You can use the DirLock class to acquire and release locks in your Python code. The class also supports usage within a with clause for convenience.

Example: Using the Lock Explicitly

import time
from dirlock import DirLock

lock_dir_path = "/tmp/mylockdir.lock"
lock = DirLock(lock_dir_path)

print("Acquire lock...")
lock.acquire()
print("Lock acquired!")

# Perform critical section tasks here
# Simulating work
time.sleep(5)

# Release the lock
lock.release()
print("Lock released.")

Example: Using the Lock in a with Clause

import time
from dirlock import DirLock

lock_dir_path = "/tmp/mylockdir.lock"

with DirLock(lock_dir_path) as lock:
    print("Lock acquired!")
    # Perform critical section tasks
    time.sleep(5)  # Simulate work
    print("Work done!")

# The lock is automatically released when the block exits.
print("Lock released.")

Parameters

  • lock_dir (str): The path to the lock directory.
  • retry_interval (float, default=0.1): Time to wait before retrying if the lock cannot be acquired.
  • timeout_interval (float, default=-1): Timeout for acquiring lock. Set to negative value for no timeout.

Change Default Values

You can change the default value for retry_interval via DirLock.retry_interval=<new_value>.

License

This package is licensed under the MIT License.

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

dirlock-0.2.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

dirlock-0.2-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file dirlock-0.2.tar.gz.

File metadata

  • Download URL: dirlock-0.2.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for dirlock-0.2.tar.gz
Algorithm Hash digest
SHA256 7d67053f5f90dc4b5117bb8f33f19d0eb271ffdea92ce38e1de435984934aa22
MD5 3f9a766ed60c1a4602b397dd63ea1650
BLAKE2b-256 51b2cfaf0ec053826db5c6e70aa00768fe4f3bef943df5ad23eafbd47816417d

See more details on using hashes here.

Provenance

The following attestation bundles were made for dirlock-0.2.tar.gz:

Publisher: python-publish.yml on z3rone-org/dirlock

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dirlock-0.2-py3-none-any.whl.

File metadata

  • Download URL: dirlock-0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for dirlock-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 12bd07cba3964deed3ab95da27801644a19248bb8b3ca1a3e1e76dc01c6efda4
MD5 2d484664ffa372366786589222257ea5
BLAKE2b-256 9f847a8cbb4b4f7e30dfdb0f10361d270ae836a4bfc7d8bb4c3fe5c778472c23

See more details on using hashes here.

Provenance

The following attestation bundles were made for dirlock-0.2-py3-none-any.whl:

Publisher: python-publish.yml on z3rone-org/dirlock

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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