A simple directory based lock implementation for Python.
Project description
Dirlock
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d66ed2d8c819189abe79a346341a9d6f4e8effdfb3473611e3e91e294533f9c8
|
|
| MD5 |
625e0d6232f0ab64be7cd5ec29ab1b18
|
|
| BLAKE2b-256 |
95ea4b11fe6a6568d7933860c16bf48e29829589e7e69a744a276e2d2f5ff820
|
Provenance
The following attestation bundles were made for dirlock-0.3.tar.gz:
Publisher:
python-publish.yml on z3rone-org/dirlock
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dirlock-0.3.tar.gz -
Subject digest:
d66ed2d8c819189abe79a346341a9d6f4e8effdfb3473611e3e91e294533f9c8 - Sigstore transparency entry: 448975978
- Sigstore integration time:
-
Permalink:
z3rone-org/dirlock@da089af0ae71a0d5f0537c78975808a36734e86f -
Branch / Tag:
refs/tags/v0.3 - Owner: https://github.com/z3rone-org
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@da089af0ae71a0d5f0537c78975808a36734e86f -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65ada1bcb5ee178b852007be13626bac97bf6a6f6ebc233ee876db5e5be4e270
|
|
| MD5 |
6fe413297c26c4c5f6bd7c18e0eb9180
|
|
| BLAKE2b-256 |
8860ba027b1bd263d169346f8be536a5509ddb790c75a61e47f09c3b7d143e5c
|
Provenance
The following attestation bundles were made for dirlock-0.3-py3-none-any.whl:
Publisher:
python-publish.yml on z3rone-org/dirlock
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dirlock-0.3-py3-none-any.whl -
Subject digest:
65ada1bcb5ee178b852007be13626bac97bf6a6f6ebc233ee876db5e5be4e270 - Sigstore transparency entry: 448976002
- Sigstore integration time:
-
Permalink:
z3rone-org/dirlock@da089af0ae71a0d5f0537c78975808a36734e86f -
Branch / Tag:
refs/tags/v0.3 - Owner: https://github.com/z3rone-org
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@da089af0ae71a0d5f0537c78975808a36734e86f -
Trigger Event:
release
-
Statement type: