Repository navigation
fix(python): use weak per-object locks instead of stripes - #5039
Merged
Merged
Conversation
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.
The fixed stripes in #5035 can make distinct lock objects share an
RLock, adding contention and potentially introducing lock dependencies into otherwise independent nested locking. Replace the stripes with a weak-value registry keyed by object identity.Lookup and creation happen under a short registry guard. Each caller keeps a strong reference to its selected
RLockwhile waiting and executing, so an active lock cannot disappear. The guard is released before acquisition and user code. Weak references target the locks, so arbitrary unhashable and non-weak-referenceable lock objects remain supported.This changes the decision documented beside the implementation: there is no fixed capacity or stripe collision, and unused entries disappear when their lock references are released. Separate calls can recreate locks; this deliberately avoids adding a pool or manual reference counting. Remove the unused runtime
MAX_LOCKSconstant; the former stripe count belongs only to the collision regression helper, and the cleanup test uses its own iteration count.The generated F# regressions now check that distinct objects which collided under the old stripe mapping acquire independently, that an active entry survives, and that idle entries are reclaimed after successful calls and exceptions. Existing contention, reentrancy, return-value, and exception tests remain.
Describe the child-timeout behavior directly in
_start_child_timeout, removing the comment about a previous implementation.Validation:
util.py, retaining the existing Rust extension.Expected: False - Actual: True).TestMisc.py; the latter retains one existing TypeVar warning. Full generated checking reports the same 34 errors / 45 warnings reported by fix(python): share per-object locks and align StartChild timeouts #5035.RUF022export-list finding, source Fantomas, andgit diff --checkpass. The export-list finding was also verified against the parent version. Repository Fantomas policy excludestests/**.Event loop is closed) outside the changed code, plus a generated syntax warning. All tests passed.Targets
fix/python-lock-stripes, the branch for #5035, so this PR shows only the proposed alternative.