Conversation
Keep the published wrapper statistics dict stable for decorator compatibility while preventing concurrent and re-entrant calls from sharing their live retry state. Fixes jd#701.
This branch has not been deployed
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.
Fixes #701.
Concurrent calls to the same synchronous retry wrapper currently share the wrapper's live statistics dict. A deterministic regression shows thread A at attempt 2 observing its attempt number change to 1 when thread B enters the same wrapper. Re-entrant calls have the same problem.
Each call now keeps its own statistics dict. Changes are mirrored to the stable wrapped_f.statistics object so the behavior fixed by #519, including visibility through outer functools.wraps decorators and during execution, is preserved. A per-thread stack restores the outer call's statistics after a nested call, and publishing to the stable wrapper dict is serialized.
This is intentionally limited to synchronous BaseRetrying.wraps(); async task-local semantics are unchanged.
There is an earlier implementation in #702. The main difference is that #702 changes the existing live-statistics regression to read retry.statistics instead of wrapped statistics. This PR preserves that existing behavior and adds an explicit re-entrant regression, rather than weakening the current wrapper-statistics contract.
Validation: PYTHONPATH=$PWD .venv/bin/poe all passes Ruff, formatting, Mypy, all 186 tests, Sphinx doctests (35/35), and the HTML docs build.