tracker¶
Cross-process lock manager backed by SQLite.
The entire lock acquisition is a single INSERT ... ON CONFLICT DO UPDATE
... WHERE (UPSERT) statement — one SQL, one rowcount check, truly atomic.
The locks table is created lazily on first OperationalError.
- class sayt2.tracker.Tracker(db_path: Path)[source]¶
SQLite-backed cross-process lock manager.
A single
.dbfile can manage locks for multiple datasets (one row per dataset name). The table and parent directories are created lazily on first use.- Parameters:
db_path – Path to the SQLite database file.
- lock_it(name: str, expire: int = 60) str[source]¶
Atomically acquire a lock for name using a single UPSERT.
rowcount == 1→ lock acquired (new row or unlocked/expired row).rowcount == 0→ lock is actively held →TrackerIsLockedError.
- Returns:
The lock token (UUID hex).
- Raises:
TrackerIsLockedError – if the lock is held by another process.