Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-128384: Use contextvar for catch_warnings()#128463

Closed
nascheme wants to merge 4 commits into
python:mainpython/cpython:mainfrom
nascheme:catch_warnings_contextvarnascheme/cpython:catch_warnings_contextvarCopy head branch name to clipboard
Closed

gh-128384: Use contextvar for catch_warnings()#128463
nascheme wants to merge 4 commits into
python:mainpython/cpython:mainfrom
nascheme:catch_warnings_contextvarnascheme/cpython:catch_warnings_contextvarCopy head branch name to clipboard

Conversation

@nascheme

@nascheme nascheme commented Jan 3, 2025

Copy link
Copy Markdown
Member

This changes warnings.catch_warnings() to use a contextvar for the new list of filters. If catch_warnings is not used, the list of filters is the module global warnings.filters. When the context manager is active, the effective list of filters is warnings.get_context()._filters.

This change is on top of two other unmerged PRs:


📚 Documentation preview 📚: https://cpython-previews--128463.org.readthedocs.build/

By default, inherit the context from the thread calling
`Thread.start()`.
Expose the mutex from _warnings.c and hold it when mutating the filters
list or the filters version.
@nascheme

Copy link
Copy Markdown
Member Author

Implemented in GH-130010.

@nascheme nascheme closed this Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.