You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# This workflow will upload a Python Package to PyPI when a release is created
2
+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3
+
4
+
# This workflow uses actions that are not certified by GitHub.
5
+
# They are provided by a third-party and are governed by
6
+
# separate terms of service, privacy policy, and support
7
+
# documentation.
8
+
9
+
name: Upload Python Package
10
+
11
+
on:
12
+
release:
13
+
types: [published]
14
+
15
+
permissions:
16
+
contents: read
17
+
18
+
jobs:
19
+
release-build:
20
+
runs-on: ubuntu-latest
21
+
22
+
steps:
23
+
- uses: actions/checkout@v4
24
+
25
+
- uses: actions/setup-python@v5
26
+
with:
27
+
python-version: "3.x"
28
+
29
+
- name: Build release distributions
30
+
run: |
31
+
# NOTE: put your own distribution build steps here.
32
+
python -m pip install build
33
+
python -m build
34
+
35
+
- name: Upload distributions
36
+
uses: actions/upload-artifact@v4
37
+
with:
38
+
name: release-dists
39
+
path: dist/
40
+
41
+
pypi-publish:
42
+
runs-on: ubuntu-latest
43
+
needs:
44
+
- release-build
45
+
permissions:
46
+
# IMPORTANT: this permission is mandatory for trusted publishing
47
+
id-token: write
48
+
49
+
# Dedicated environments with protections for publishing are strongly recommended.
50
+
# For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
51
+
environment:
52
+
name: pypi
53
+
# OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
54
+
# url: https://pypi.org/p/YOURPROJECT
55
+
#
56
+
# ALTERNATIVE: if your GitHub Release name is the PyPI project version string
57
+
# ALTERNATIVE: exactly, uncomment the following line instead:
A simple directory-based lock implementation for Python. This package provides a lightweight and effective way
7
+
to coordinate access to shared resources using a lock directory mechanism.
8
+
This does not require any file locking capabilities of the underlying filesystem or network share.
9
+
10
+
## Installation
11
+
12
+
Install the package via pip:
13
+
14
+
```bash
15
+
pip install dirlock
16
+
```
17
+
18
+
## Usage
19
+
20
+
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.
21
+
22
+
### Example: Using the Lock Explicitly
23
+
24
+
```python
25
+
import time
26
+
from dirlock import DirLock
27
+
28
+
lock_dir_path ="/tmp/mylockdir.lock"
29
+
lock = DirLock(lock_dir_path)
30
+
31
+
print("Acquire lock...")
32
+
lock.acquire()
33
+
print("Lock acquired!")
34
+
35
+
# Perform critical section tasks here
36
+
# Simulating work
37
+
time.sleep(5)
38
+
39
+
# Release the lock
40
+
lock.release()
41
+
print("Lock released.")
42
+
```
43
+
44
+
### Example: Using the Lock in a `with` Clause
45
+
46
+
```python
47
+
import time
48
+
from dirlock import DirLock
49
+
50
+
lock_dir_path ="/tmp/mylockdir.lock"
51
+
52
+
with DirLock(lock_dir_path) as lock:
53
+
print("Lock acquired!")
54
+
# Perform critical section tasks
55
+
time.sleep(5) # Simulate work
56
+
print("Work done!")
57
+
58
+
# The lock is automatically released when the block exits.
59
+
print("Lock released.")
60
+
```
61
+
62
+
## Parameters
63
+
64
+
-`lock_dir` (str): The path to the lock directory.
65
+
-`retry_interval` (float, default=0.1): Time to wait before retrying if the lock cannot be acquired.
66
+
-`timeout_interval` (float, default=-1): Timeout for acquiring lock. Set to negative value for no timeout.
67
+
68
+
## Change Default Values
69
+
You can change the default value for `retry_interval`
0 commit comments