tbot_contrib.locking
¶
This module provide utilities for managing “locks” on the lab-host. This can be used in setups where multiple users might try accessing the same host at the same time. Instead of cryptic errors due to busy devices or, even worse, bad behavior because of two running tbot testcases interfering, only one can ever access, for example, a board.
To facilitate this, two parts are needed:
The lab-host configuration must be augmented with the
LockManager
mixin. This provides a locking “implementation” which board machines can hook into.To enable locking for a certain board, it should inherit the
MachineLock
mixin.
- class tbot_contrib.locking.MachineLock[source]¶
Bases:
PreConnectInitializer
This is the initializer that is inherited by the board machine. It just calls the lab-host’s locking implementation.
New in version 0.9.1.
- class tbot_contrib.locking.LockManager[source]¶
Bases:
LockManagerBase
,PostShellInitializer
,LinuxShell
Machine locking implementation based on Python, bash and flock(1)
New in version 0.9.1.
- lock_checkpid: bool = True¶
Make tbot check whether the PID associated with a lockfile is still alive.
If this check is enabled and the PID is found, the lock will be considered active, even if it would otherwise have been assumed expired.
- property lock_dir: Path¶
The directory where tbot locks are stored.
Defaults to
/tmp/tbot-locks
. If this directory does not exist, it will be created and given0777
access mode to allow all users to write lockfiles to it.
- request_machine_lock(name: str, *, expiry: int | None = None) bool [source]¶
Request lock for machine named
name
.This method will usually be called via the
MachineLock
mixin.- Parameters:
- Returns:
True
if the lock has been acquired successfully andFalse
otherwise.
- release_machine_lock(name: str) None [source]¶
Release lock for machine named
name
.If not explicitly released, the
LockManager
will automatically unlock all locks it is holding when the lab-host machine is deinitialized.