René's URL Explorer Experiment


Title: gh-128384: Add locking to warnings.py. by nascheme · Pull Request #128386 · python/cpython · GitHub

Open Graph Title: gh-128384: Add locking to warnings.py. by nascheme · Pull Request #128386 · python/cpython

X Title: gh-128384: Add locking to warnings.py. by nascheme · Pull Request #128386 · python/cpython

Description: 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? Issue: gh-128384

Open Graph Description: 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 updati...

X Description: 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 updati...

Opengraph URL: https://github.com/python/cpython/pull/128386

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:986587e2-706c-ab7f-5da5-1e79e6de297d
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idE47E:3F1247:F90FB4:155620D:6A53BE3B
html-safe-nonce9d5b575f2314f2ab3247aa8bca312c69d4595c4951a6b2f0b84507ccc2effe96
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNDdFOjNGMTI0NzpGOTBGQjQ6MTU1NjIwRDo2QTUzQkUzQiIsInZpc2l0b3JfaWQiOiIzODQwMjYyNTY3NjA1MDI2MzYzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacccfeb4bb9df015804f0bc883cd622765ba8c0324828ef35779b6dd656352724f
hovercard-subject-tagpull_request:2256750134
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/128386/files
twitter:imagehttps://avatars.githubusercontent.com/u/690853?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/690853?s=400&v=4
og:image:altThe 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 updati...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release07a982c1d40157c619b364352b704c3ce66bb332
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/128386/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F128386%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F128386%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/128386/files
Reloadhttps://github.com/python/cpython/pull/128386/files
Reloadhttps://github.com/python/cpython/pull/128386/files
Please reload this pagehttps://github.com/python/cpython/pull/128386/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/128386/files
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 35k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 73.8k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.3k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality 0 https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
naschemehttps://github.com/nascheme
python:mainhttps://github.com/python/cpython/tree/main
nascheme:warnings_lockhttps://github.com/nascheme/cpython/tree/warnings_lock
Conversation 18 https://github.com/python/cpython/pull/128386
Commits 11 https://github.com/python/cpython/pull/128386/commits
Checks 0 https://github.com/python/cpython/pull/128386/checks
Files changed https://github.com/python/cpython/pull/128386/files
Please reload this pagehttps://github.com/python/cpython/pull/128386/files
gh-128384: Add locking to warnings.py. https://github.com/python/cpython/pull/128386/files#top
Show all changes 11 commits https://github.com/python/cpython/pull/128386/files
deb659d Add locking to warnings.py. nascheme Dec 27, 2024 https://github.com/python/cpython/pull/128386/commits/deb659dd1177e1a537fd25da94576e6e4ea32028
d5187b3 Rename function, add locking to _filters_mutated(). nascheme Jan 1, 2025 https://github.com/python/cpython/pull/128386/commits/d5187b3c43a83176041e1c67b47a19b7ec0e87a1
553d04f Use re-entrant lock for warnings module. nascheme Jan 1, 2025 https://github.com/python/cpython/pull/128386/commits/553d04f5c8738a4a3dc396f8551d0845a4c195c2
4b56ae6 Fix locking for !Py_GIL_DISABLED build. nascheme Jan 2, 2025 https://github.com/python/cpython/pull/128386/commits/4b56ae6096b2c23b3740862f7c8f6927cd6f638c
6100ab2 Add blurb. nascheme Jan 6, 2025 https://github.com/python/cpython/pull/128386/commits/6100ab23607ecd8a8504d1c9ce22bb1333fde173
b9db71f Fix typo. nascheme Jan 6, 2025 https://github.com/python/cpython/pull/128386/commits/b9db71f3010a211d9933f75a293f19b4801d3a6a
27e3acd Update Misc/NEWS.d/next/Library/2025-01-06-10-37-27.gh-issue-128384.V… nascheme Jan 7, 2025 https://github.com/python/cpython/pull/128386/commits/27e3acdb4eb436ae22e469e858c07d9a1ee81c57
dcdb699 Merge branch 'main' into warnings_lock nascheme Jan 7, 2025 https://github.com/python/cpython/pull/128386/commits/dcdb699a9744aea7bf8b5d60b6e623dd2994f914
441b1ae Use locking for GIL build as well. nascheme Jan 7, 2025 https://github.com/python/cpython/pull/128386/commits/441b1ae32be226158d412b35d7ce14356c096e56
9bd8875 Update Python/_warnings.c nascheme Jan 12, 2025 https://github.com/python/cpython/pull/128386/commits/9bd8875bf9575a62d97aa5fde72bc3a3ea927cc8
5b19978 Hold lock while assigning self._module methods. nascheme Jan 14, 2025 https://github.com/python/cpython/pull/128386/commits/5b199787b87055d5b314323e568c19411f700a5a
Clear filters https://github.com/python/cpython/pull/128386/files
Please reload this pagehttps://github.com/python/cpython/pull/128386/files
Please reload this pagehttps://github.com/python/cpython/pull/128386/files
pycore_warnings.h https://github.com/python/cpython/pull/128386/files#diff-4aacd6399c9c463b24a64311fb5b80b3666304d99b1224422074e66046bcaa3e
__init__.py https://github.com/python/cpython/pull/128386/files#diff-21be9e4809f5cd7dcd4665eb0054b4bf9d924c2c9ce0a010e85dba405e94d9e9
warnings.py https://github.com/python/cpython/pull/128386/files#diff-1d0c2ffbcb01254c4ab02053d85527be50e03ea2908dc6cdba9fc185b8df9b7b
2025-01-06-10-37-27.gh-issue-128384.V0xzwH.rst https://github.com/python/cpython/pull/128386/files#diff-10bb88cce95e8c79493ccb8e7ae20f571a2976bd549a138b03e04032ff8fe9b1
_warnings.c https://github.com/python/cpython/pull/128386/files#diff-868cb9c3ec7f49459c652319e480e03ee132976b45fbedacb94958f8e0a9ea58
_warnings.c.h https://github.com/python/cpython/pull/128386/files#diff-12950f5bbdc079cc0b7edd3b04cb1b2e5a7de0eb4964fe861e3c4acc5f0675a0
Include/internal/pycore_warnings.hhttps://github.com/python/cpython/pull/128386/files#diff-4aacd6399c9c463b24a64311fb5b80b3666304d99b1224422074e66046bcaa3e
View file https://github.com/nascheme/cpython/blob/5b199787b87055d5b314323e568c19411f700a5a/Include/internal/pycore_warnings.h
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/128386/{{ revealButtonHref }}
https://github.com/python/cpython/pull/128386/files#diff-4aacd6399c9c463b24a64311fb5b80b3666304d99b1224422074e66046bcaa3e
https://github.com/python/cpython/pull/128386/files#diff-4aacd6399c9c463b24a64311fb5b80b3666304d99b1224422074e66046bcaa3e
Lib/test/test_warnings/__init__.pyhttps://github.com/python/cpython/pull/128386/files#diff-21be9e4809f5cd7dcd4665eb0054b4bf9d924c2c9ce0a010e85dba405e94d9e9
View file https://github.com/nascheme/cpython/blob/5b199787b87055d5b314323e568c19411f700a5a/Lib/test/test_warnings/__init__.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/128386/{{ revealButtonHref }}
https://github.com/python/cpython/pull/128386/files#diff-21be9e4809f5cd7dcd4665eb0054b4bf9d924c2c9ce0a010e85dba405e94d9e9
https://github.com/python/cpython/pull/128386/files#diff-21be9e4809f5cd7dcd4665eb0054b4bf9d924c2c9ce0a010e85dba405e94d9e9
Lib/warnings.pyhttps://github.com/python/cpython/pull/128386/files#diff-1d0c2ffbcb01254c4ab02053d85527be50e03ea2908dc6cdba9fc185b8df9b7b
View file https://github.com/nascheme/cpython/blob/5b199787b87055d5b314323e568c19411f700a5a/Lib/warnings.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/128386/{{ revealButtonHref }}
https://github.com/python/cpython/pull/128386/files#diff-1d0c2ffbcb01254c4ab02053d85527be50e03ea2908dc6cdba9fc185b8df9b7b
https://github.com/python/cpython/pull/128386/files#diff-1d0c2ffbcb01254c4ab02053d85527be50e03ea2908dc6cdba9fc185b8df9b7b
https://github.com/python/cpython/pull/128386/files#diff-1d0c2ffbcb01254c4ab02053d85527be50e03ea2908dc6cdba9fc185b8df9b7b
https://github.com/python/cpython/pull/128386/files#diff-1d0c2ffbcb01254c4ab02053d85527be50e03ea2908dc6cdba9fc185b8df9b7b
https://github.com/python/cpython/pull/128386/files#diff-1d0c2ffbcb01254c4ab02053d85527be50e03ea2908dc6cdba9fc185b8df9b7b
https://github.com/python/cpython/pull/128386/files#diff-1d0c2ffbcb01254c4ab02053d85527be50e03ea2908dc6cdba9fc185b8df9b7b
https://github.com/python/cpython/pull/128386/files#diff-1d0c2ffbcb01254c4ab02053d85527be50e03ea2908dc6cdba9fc185b8df9b7b
Please reload this pagehttps://github.com/python/cpython/pull/128386/files
https://github.com/python/cpython/pull/128386/files#diff-1d0c2ffbcb01254c4ab02053d85527be50e03ea2908dc6cdba9fc185b8df9b7b
Misc/NEWS.d/next/Library/2025-01-06-10-37-27.gh-issue-128384.V0xzwH.rsthttps://github.com/python/cpython/pull/128386/files#diff-10bb88cce95e8c79493ccb8e7ae20f571a2976bd549a138b03e04032ff8fe9b1
View file https://github.com/nascheme/cpython/blob/5b199787b87055d5b314323e568c19411f700a5a/Misc/NEWS.d/next/Library/2025-01-06-10-37-27.gh-issue-128384.V0xzwH.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/128386/{{ revealButtonHref }}
Please reload this pagehttps://github.com/python/cpython/pull/128386/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.