GeezerVison is showing github.com — gh-128384: Add locking to warnings.py. by nascheme · Pull Request #128386 · python/cpython
Conversation
nascheme
commented
Dec 31, 2024
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
The warnings module has some (relatively minor) thread safety issues. The catch_warnings contex manager is a major issue but that will be handled in a different PR. There are races between updating the filters list and incrementing the _filters_version number. Also, the warn_explicit() uses the global state in a non-thread-safe way. These issues are relatively easy to fix with some extra locking.
Changes:
- expose the mutex used by the
_warnings module, as _acquire_lock and _release_lock
- implement a lock context manager and lock module state as needed
- fix a bug in
DeprecatedTests that resulted in mixing py_warnings and c_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?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Expose the mutex from _warnings.c and hold it when mutating the filters
list.
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?
I think the lock should be re-entrant, as locks are held when doing dict lookups which can call arbitrary python code.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
This looks good now from a brief look.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|