hwlock
Coordinate exclusive access to a physical hardware resource shared by multiple local processes. hwlock provides a cooperative mutex with a priority-aware FIFO queue for development boards, serial consoles, JTAG probes, programmers, and similar one-at-a-time resources.
It is daemon-free and dependency-free: state is stored in files and guarded with flock.
Requirements
- Linux or another POSIX host with Python 3.10+
- All resource users must cooperate by running their hardware operation through
hwlock
Install
python3 -m pip install hwlock
Usage
Run a command while holding a resource lock:
hwlock exec --resource g2-proto --label firmware-flash -- ./flash.sh
exec waits for the resource, runs the command, propagates its exit status, and releases the lock afterward.
For workflows that span several commands, acquire and release a lease explicitly:
hwlock acquire --resource g2-proto --label debug-session
# use the board
hwlock release --resource g2-proto --label debug-session
The same label is required to release a lease, preventing one user from accidentally releasing another user's lock.
Inspect current use and queues:
hwlock status
hwlock status --resource g2-proto
hwlock list
Use high priority for urgent recovery work. It moves ahead of queued normal-priority waiters but never interrupts the current holder:
hwlock exec --resource g2-proto --label recovery \
--priority high --timeout 120 -- ./recover.sh
Clear a leaked lease only after confirming that no hardware operation is still running:
hwlock force-release --resource g2-proto
Commands
acquire: wait for and retain a lease until a matchingreleaserelease: release a lease held by the same labelexec: hold the resource for the lifetime of a commandstatus: show holders and queued waiterslist: list known resourcesforce-release: clear holder metadata without checking its owner
Run hwlock <command> --help for command-specific options.
State
State defaults to ~/.cache/hwlock. Set HWLOCK_STATE_DIR to isolate a different coordination domain:
HWLOCK_STATE_DIR=/tmp/team-hwlock hwlock status
Locks coordinate processes on one host only. They do not prevent access from other machines or programs that bypass hwlock.
Development
python3 -m pip install -e '.[dev]'
pytest -q
python3 -m build
Release
Pushing a tag matching v* runs .github/workflows/publish.yml. The workflow builds the distributions and publishes them to PyPI using trusted publishing; it does not store a PyPI API token.
Configure the PyPI trusted publisher with:
- PyPI project:
hwlock - GitHub owner:
XuNeo - Repository:
hwlock - Workflow:
publish.yml - Environment:
pypi
License
MIT
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 hwlock-0.1.0.tar.gz.
File metadata
- Download URL: hwlock-0.1.0.tar.gz
- Upload date:
- Size: 16.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a229b92c4c0b9fc4eaa64145282045b00691e5e1022030057388a5b747eda74
|
|
| MD5 |
b76e2eb48be8f992c525193f332a4906
|
|
| BLAKE2b-256 |
6f7b89b446223db9775aba55858dc9121d85b2405b7e7b4b90d1459f7d40f2c4
|
Provenance
The following attestation bundles were made for hwlock-0.1.0.tar.gz:
Publisher:
publish.yml on XuNeo/hwlock
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hwlock-0.1.0.tar.gz -
Subject digest:
7a229b92c4c0b9fc4eaa64145282045b00691e5e1022030057388a5b747eda74 - Sigstore transparency entry: 2310507015
- Sigstore integration time:
-
Permalink:
XuNeo/hwlock@93ca4297630ff5296578380cc486b0e9f52d3d73 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/XuNeo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@93ca4297630ff5296578380cc486b0e9f52d3d73 -
Trigger Event:
push
-
Statement type:
File details
Details for the file hwlock-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hwlock-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81debe865c10736bb875c6470f068ddffe3c60ec0e2b016e21a06fc9328de110
|
|
| MD5 |
8afc755eb274279f99c5ae12a43cddf8
|
|
| BLAKE2b-256 |
7dd1e77bf3a6fd207f54f2243b3dc7f7e7fac2161fd5583e56aee3a043f4411e
|
Provenance
The following attestation bundles were made for hwlock-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on XuNeo/hwlock
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hwlock-0.1.0-py3-none-any.whl -
Subject digest:
81debe865c10736bb875c6470f068ddffe3c60ec0e2b016e21a06fc9328de110 - Sigstore transparency entry: 2310507025
- Sigstore integration time:
-
Permalink:
XuNeo/hwlock@93ca4297630ff5296578380cc486b0e9f52d3d73 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/XuNeo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@93ca4297630ff5296578380cc486b0e9f52d3d73 -
Trigger Event:
push
-
Statement type: