✨ feat(soft): add PID inspection and lock breaking#524
Merged
gaborbernat merged 4 commits intotox-dev:mainfrom Apr 6, 2026
Merged
✨ feat(soft): add PID inspection and lock breaking#524gaborbernat merged 4 commits intotox-dev:mainfrom
gaborbernat merged 4 commits intotox-dev:mainfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Users migrating from the deprecated
lockfilelibrary'sPIDLockFileneed equivalent functionality in filelock.SoftFileLockalready 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: apidproperty that reads the lock holder's PID from the lock file, ani_am_lockingproperty that checks whether the current process holds the lock, and abreak_lock()method that unconditionally removes the lock file. These map directly to thePIDLockFileAPI that users are familiar with, using properties instead of methods where appropriate.🔧 The metaclass
__call__return type was also changed from a concreteBaseFileLockto aTypeVarbound to the base class. This meansSoftFileLock(...)is now correctly typed as returningSoftFileLockrather thanBaseFileLock, which allows type checkers to see subclass-specific attributes without casts. A ty bug withsuper()in TypeVar-typed metaclass methods was discovered and reported during this work.Closes #521