build_lock#

scikitplot.cython.build_lock(lock_dir, *, timeout_s=60.0, poll_s=0.05)[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 0 makes a single acquisition attempt and raises TimeoutError immediately if the lock is already held.

poll_sfloat, default=0.05

Sleep interval in seconds between acquisition retries.

Returns:
Iterator[None]

Context manager that yields once the lock is held.

Raises:
TimeoutError

If the lock cannot be acquired within timeout_s seconds.

ValueError

If timeout_s < 0 or poll_s <= 0.

Parameters:
Return type:

Iterator[None]

Notes

Stale lock recovery: if a lock directory exists but its mtime is older than timeout_s seconds, it is treated as stale (left by a killed process) and removed before the next acquisition attempt. This prevents permanent deadlock after hard crashes.

Clean release: the lock directory is always removed in the finally block, so normal exceptions inside the with body release the lock correctly.