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.1.tar.gz (4.4 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.1-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dirlock-0.1.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for dirlock-0.1.tar.gz
Algorithm Hash digest
SHA256 d398de144ed274f1b1a655068afa38b992fb41fa2975327a6cde406dc50c5153
MD5 c1168d691b559246aa4403e1514c8441
BLAKE2b-256 e99b5c2fbf4e84e79452b82d1f09e32f58a090c0862b544775cdc6607a3c10ff

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: dirlock-0.1-py3-none-any.whl
  • Upload date:
  • Size: 2.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for dirlock-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3bf43e95098f4017eda34d4c6a024616e35d93c46d4c6cbce47e6941db51e6ba
MD5 dd7ef92549d3e3bf076451b26c62b3c0
BLAKE2b-256 3c8263002318caf435385e7eb76046bbca612f615ef51ff841b0979368c5aa65

See more details on using hashes here.

Provenance

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