-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-128384: Add locking to warnings.py. #128386
Draft
nascheme
wants to merge
4
commits into
python:main
Choose a base branch
from
nascheme:warnings_lock
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains 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
Expose the mutex from _warnings.c and hold it when mutating the filters list.
nascheme
force-pushed
the
warnings_lock
branch
from
December 31, 2024 23:24
a5ec58d
to
deb659d
Compare
I think the lock should be re-entrant, as locks are held when doing dict lookups which can call arbitrary python code. |
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
warnings
module has some (relatively minor) thread safety issues. Thecatch_warnings
contex manager is a major issue but that will be handled in a different PR. There are races between updating thefilters
list and incrementing the_filters_version
number. Also, thewarn_explicit()
uses the global state in a non-thread-safe way. These issues are relatively easy to fix with some extra locking.Changes:
_warnings
module, as_acquire_lock
and_release_lock
DeprecatedTests
that resulted in mixingpy_warnings
andc_warnings
modules.The mutex used is non-reentrant and so some care is required to avoid deadlocks. I restructured the code in
warn_explicit()
to reduce functions called within the locked section. Perhaps a re-entrant lock should be used instead?