-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-128384: Add locking to warnings.py. #128386
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
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
Expose the mutex from _warnings.c and hold it when mutating the filters list.
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. |
Misc/NEWS.d/next/Library/2025-01-06-10-37-27.gh-issue-128384.V0xzwH.rst
Outdated
Show resolved
Hide resolved
…0xzwH.rst Co-authored-by: Kumar Aditya <[email protected]>
Co-authored-by: Kumar Aditya <[email protected]>
This looks good now from a brief look. |
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?