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.3.tar.gz (6.8 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.3-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for dirlock-0.3.tar.gz
Algorithm Hash digest
SHA256 d66ed2d8c819189abe79a346341a9d6f4e8effdfb3473611e3e91e294533f9c8
MD5 625e0d6232f0ab64be7cd5ec29ab1b18
BLAKE2b-256 95ea4b11fe6a6568d7933860c16bf48e29829589e7e69a744a276e2d2f5ff820

See more details on using hashes here.

Provenance

The following attestation bundles were made for dirlock-0.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: dirlock-0.3-py3-none-any.whl
  • Upload date:
  • Size: 3.7 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 65ada1bcb5ee178b852007be13626bac97bf6a6f6ebc233ee876db5e5be4e270
MD5 6fe413297c26c4c5f6bd7c18e0eb9180
BLAKE2b-256 8860ba027b1bd263d169346f8be536a5509ddb790c75a61e47f09c3b7d143e5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for dirlock-0.3-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