Skip to main content

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 matching release
  • release: release a lease held by the same label
  • exec: hold the resource for the lifetime of a command
  • status: show holders and queued waiters
  • list: list known resources
  • force-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.

Claude Code skill

The matching Claude Code skill is published in skills/. Copy that directory to your local skills directory:

git clone https://github.com/XuNeo/hwlock.git
cp -R hwlock/skills ~/.claude/skills/hwlock

The skill instructs hardware workflows to use hwlock and to run pip install hwlock when the command is not installed.

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

Metadata

Release files for hwlock 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hwlock 0.1.1
File Size Uploaded
hwlock-0.1.1.tar.gz 20.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hwlock 0.1.1
File Interpreter ABI Platform
hwlock-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 34.1 kB

Release files / hwlock-0.1.1.tar.gz

Download URL hwlock-0.1.1.tar.gz
Size 20.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b67a6e75b30836c98baf531732762c67c88079d5f0762c9de1fef50d9cbd449b
BLAKE2b-256 checksum
How to use checksums
bd24a2ae216eeb841415696ed835afa083a04dd88fcbce2c56400c60a61159c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.

Transparency log

Release files / hwlock-0.1.1-py3-none-any.whl

Download URL hwlock-0.1.1-py3-none-any.whl
Size 13.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9e33922038ed2b7e5bcac88eb1c17ae678da8dd3d7665490a8264696a99d9c53
BLAKE2b-256 checksum
How to use checksums
58a4e571fcf0cbb2a945a76f8cbf8f12685ed535e9597051fd70d8c6e1c206a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.2

2 release files

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page