Skip to content

✨ feat(soft): add PID inspection and lock breaking#524

Merged
gaborbernat merged 4 commits intotox-dev:mainfrom
gaborbernat:feat/pid-lock-api
Apr 6, 2026
Merged

✨ feat(soft): add PID inspection and lock breaking#524
gaborbernat merged 4 commits intotox-dev:mainfrom
gaborbernat:feat/pid-lock-api

Conversation

@gaborbernat
Copy link
Copy Markdown
Member

@gaborbernat gaborbernat commented Apr 6, 2026

Users migrating from the deprecated lockfile library's PIDLockFile need equivalent functionality in filelock. SoftFileLock already writes the PID and hostname to the lock file for stale lock detection, but there was no public API to read that information or forcibly break a lock. This addresses #521.

✨ Three new public members on SoftFileLock: a pid property that reads the lock holder's PID from the lock file, an i_am_locking property that checks whether the current process holds the lock, and a break_lock() method that unconditionally removes the lock file. These map directly to the PIDLockFile API that users are familiar with, using properties instead of methods where appropriate.

🔧 The metaclass __call__ return type was also changed from a concrete BaseFileLock to a TypeVar bound to the base class. This means SoftFileLock(...) is now correctly typed as returning SoftFileLock rather than BaseFileLock, which allows type checkers to see subclass-specific attributes without casts. A ty bug with super() in TypeVar-typed metaclass methods was discovered and reported during this work.

Closes #521

Users migrating from the deprecated `lockfile.PIDLockFile` need a way
to read the lock holder's PID, check ownership, and forcibly break
stale locks. SoftFileLock already writes PID+hostname to the lock file
but had no public API to access it.

Add `pid` property, `i_am_locking` property, and `break_lock()` method
to SoftFileLock. Also fix the metaclass `__call__` return type to use a
TypeVar so type checkers preserve the subclass type (SoftFileLock(...)
returns SoftFileLock, not BaseFileLock).

Closes tox-dev#521
@gaborbernat gaborbernat merged commit f8a9849 into tox-dev:main Apr 6, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add PidLockFile capability

1 participant