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 t113-evb --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 t113-evb --label debug-session
# use the board
hwlock release --resource t113-evb --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 t113-evb
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 t113-evb --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 t113-evb

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.2

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.2
File Size Uploaded
hwlock-0.1.2.tar.gz 20.2 kB Details

Built distribution (wheel)

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

Total release size: 33.9 kB

Release files / hwlock-0.1.2.tar.gz

Download URL hwlock-0.1.2.tar.gz
Size 20.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7c86a7c5ba1fcb14b8969595094b5272bce5e5dc2eb60e115ad90678e784ede2
BLAKE2b-256 checksum
How to use checksums
be03e0ec68b5f58470b61dcdc47a82656967585e88bfb8e12cb7734fdcc436d0
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.2-py3-none-any.whl

Download URL hwlock-0.1.2-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
08cb1af357b83d2e4db953e9d6c3da82ddeb8ff3ecc48eb1df8459174c8b2ea9
BLAKE2b-256 checksum
How to use checksums
4d8b9dd65c50fe50f642d4d376bc4da13e151a3172eed17e4af5af67b8ee46ed
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

This release

0.1.2 This release

2 release files

0.1.1

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