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.
- Linux or another POSIX host with Python 3.10+
- All resource users must cooperate by running their hardware operation through
hwlock
python3 -m pip install hwlockRun a command while holding a resource lock:
hwlock exec --resource g2-proto --label firmware-flash -- ./flash.shexec 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-sessionThe 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 listUse 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.shClear a leaked lease only after confirming that no hardware operation is still running:
hwlock force-release --resource g2-protoacquire: 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 defaults to ~/.cache/hwlock. Set HWLOCK_STATE_DIR to isolate a different coordination domain:
HWLOCK_STATE_DIR=/tmp/team-hwlock hwlock statusLocks coordinate processes on one host only. They do not prevent access from other machines or programs that bypass hwlock.
python3 -m pip install -e '.[dev]'
pytest -q
python3 -m buildPushing 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
MIT