build_lock#
- scikitplot.cython.build_lock(lock_dir, *, timeout_s=60.0, poll_s=0.05, stale_after_s=None)[source]#
Acquire an exclusive build lock via atomic directory creation.
- Parameters:
- lock_dirpathlib.Path
Lock directory path to create atomically.
- timeout_sfloat, default=60.0
Maximum seconds to wait for the lock. A value of
0makes a single acquisition attempt and raisesTimeoutErrorimmediately if the lock is already held.- poll_sfloat, default=0.05
Sleep interval in seconds between acquisition retries.
- stale_after_sfloat | None, default=None
Age in seconds after which an existing lock may be reclaimed as stale. When
None, the effective threshold ismax(timeout_s, _DEFAULT_STALE_AFTER_S).
- Returns:
- Iterator[None]
Context manager that yields once the lock is held.
- Raises:
- TimeoutError
If the lock cannot be acquired within
timeout_sseconds.- ValueError
If
timeout_s < 0,poll_s <= 0, or an explicitstale_after_s <= 0.
- Parameters:
- Return type:
Iterator[None]
Notes
Stale lock recovery: if a lock directory exists but its
mtimeis older than the effective stale threshold, it is treated as stale (left by a killed process) and removed before the next acquisition attempt. The threshold isstale_after_swhen supplied; otherwise it ismax(timeout_s, _DEFAULT_STALE_AFTER_S).Clean release: the lock directory is always removed in the
finallyblock, so normal exceptions inside thewithbody release the lock correctly.