René's URL Explorer Experiment


Title: GH-141148: ensure tasks/threads get fresh copy of decimal.Context by nascheme · Pull Request #146482 · python/cpython · GitHub

Open Graph Title: GH-141148: ensure tasks/threads get fresh copy of decimal.Context by nascheme · Pull Request #146482 · python/cpython

X Title: GH-141148: ensure tasks/threads get fresh copy of decimal.Context by nascheme · Pull Request #146482 · python/cpython

Description: Ensure that decimal.getcontext() returns a per-task copy of the decimal.Context so that mutations are isolated between asyncio tasks and threads when sys.flags.thread_inherit_context is set. This change is required because decimal.Context instances are mutable. The contextvars.Context object uses an immutable data structure (HAMT) to store variable bindings. That ensures each task has its own set of contextvar bindings. However, it doesn't help if the contextvar value itself is mutated. To fix this bug, the ContextVar.get_changed() method was added. This allows the decimal module to check if the contextvar value is newly set in this task/thread or if it is a value inherited. In the latter case, we copy the decimal.Context object to ensure that potential mutations to it are isolated. There is a downside to this change. The contextvars.Context object has gained an additional pointer value PyHamtObject *ctx_vars_origin. I think the memory overhead of that pointer itself is negligible. That reference also keeps the entries in the "origin" HAMT object alive for as long as the new context exists. That could keep some contextvar values alive for longer. I think in practice this is okay as well. Generally the contextvar values should be small objects. Also, if the task/thread that calls Context.run() is still around then the ctx_vars_origin object is likely still alive anyhow, due to that task holding a reference to it. It is only if the original task calls ContextVar.set() that you might free something. Issue: gh-141148 📚 Documentation preview 📚: https://cpython-previews--146482.org.readthedocs.build/

Open Graph Description: Ensure that decimal.getcontext() returns a per-task copy of the decimal.Context so that mutations are isolated between asyncio tasks and threads when sys.flags.thread_inherit_context is set. This c...

X Description: Ensure that decimal.getcontext() returns a per-task copy of the decimal.Context so that mutations are isolated between asyncio tasks and threads when sys.flags.thread_inherit_context is set. This c...

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

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:477ba648-9ccc-ecdf-491c-f16d5a16d662
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id970A:27A3BF:91CB5B:C7E8A9:6A5393ED
html-safe-nonce14e01e1a78fe08204049423277185957abe2e976587b0747223f668c535445d2
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NzBBOjI3QTNCRjo5MUNCNUI6QzdFOEE5OjZBNTM5M0VEIiwidmlzaXRvcl9pZCI6IjU5MTAwMjIyNzEyMTM0NzQ3OTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac549c40689deba924957cc6526f2111880033c45432683424ff0f80d4928a462c
hovercard-subject-tagpull_request:3453083668
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/146482/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:altEnsure that decimal.getcontext() returns a per-task copy of the decimal.Context so that mutations are isolated between asyncio tasks and threads when sys.flags.thread_inherit_context is set. This c...
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/146482/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F146482%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%2F146482%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/146482/files
Reloadhttps://github.com/python/cpython/pull/146482/files
Reloadhttps://github.com/python/cpython/pull/146482/files
Please reload this pagehttps://github.com/python/cpython/pull/146482/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/146482/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:decimal_ctx_inherithttps://github.com/nascheme/cpython/tree/decimal_ctx_inherit
Conversation 9 https://github.com/python/cpython/pull/146482
Commits 6 https://github.com/python/cpython/pull/146482/commits
Checks 52 https://github.com/python/cpython/pull/146482/checks
Files changed https://github.com/python/cpython/pull/146482/files
Please reload this pagehttps://github.com/python/cpython/pull/146482/files
GH-141148: ensure tasks/threads get fresh copy of decimal.Context https://github.com/python/cpython/pull/146482/files#top
Show all changes 6 commits https://github.com/python/cpython/pull/146482/files
0a20e79 Add PyContextVar_GetChanged() method. nascheme Mar 26, 2026 https://github.com/python/cpython/pull/146482/commits/0a20e79268eafd2c3d3121e912ec8f165946f750
b33469e Use ContextVar.get_changed() for decimal context. nascheme Mar 26, 2026 https://github.com/python/cpython/pull/146482/commits/b33469eb37f0746916353b539b36c2a03ea14eca
74482e3 Mark unit test that needs working threads. nascheme Mar 26, 2026 https://github.com/python/cpython/pull/146482/commits/74482e303587929b75143a6d4283a83073c88ff5
c2dbdca Remove public PyContextVar_GetChanged() API. nascheme Jun 17, 2026 https://github.com/python/cpython/pull/146482/commits/c2dbdca27fb97831bee4c23d3e9e857588d76b5e
5835fac Merge remote-tracking branch 'origin/main' into decimal_ctx_inherit nascheme Jun 17, 2026 https://github.com/python/cpython/pull/146482/commits/5835fac16d14bcce27977767956c5757232e8998
a7dacfa Merge remote-tracking branch 'origin/main' into decimal_ctx_inherit nascheme Jun 18, 2026 https://github.com/python/cpython/pull/146482/commits/a7dacfab8679fa605d9fb8037e5fb2753adff553
Clear filters https://github.com/python/cpython/pull/146482/files
Please reload this pagehttps://github.com/python/cpython/pull/146482/files
Please reload this pagehttps://github.com/python/cpython/pull/146482/files
pycore_context.h https://github.com/python/cpython/pull/146482/files#diff-eab1ba7712d90b687ef7595800ea1fbffcc4eaf34bddc447ab0fe75afd447be1
_pydecimal.py https://github.com/python/cpython/pull/146482/files#diff-fad420a37a1acebb2eb47f65bf3bd7e6aedc561cc51141bd3663c0e397d41c50
test_context.py https://github.com/python/cpython/pull/146482/files#diff-792103db84a1a30161bf2c8d994d0fc5ee17ca7635119249ba520c96d0f238a4
test_decimal.py https://github.com/python/cpython/pull/146482/files#diff-0bf3efdde952043078e322013c2459632397c6a9b312d49e70ae4a9791e2a1d8
2026-03-26-10-27-07.gh-issue-141148._XpYnI.rst https://github.com/python/cpython/pull/146482/files#diff-83cbcefa786f55deb2160941ebacb22ac1586411cfd7d827571fa1f7e2ed85d6
_decimal.c https://github.com/python/cpython/pull/146482/files#diff-071237c57ffb81dd4303eb5f02e5c5a661891a31c746c8f55a97a39659ad95d6
context.c.h https://github.com/python/cpython/pull/146482/files#diff-19e43b8bf194de9e376a91534c386f6d87608e87ce2423f9e0993028b59db4c1
context.c https://github.com/python/cpython/pull/146482/files#diff-90866884a04307bbbb14a8c99bcb5c4b96edde026113a014601b2ae38881f149
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L241
Include/internal/pycore_context.hhttps://github.com/python/cpython/pull/146482/files#diff-eab1ba7712d90b687ef7595800ea1fbffcc4eaf34bddc447ab0fe75afd447be1
View file https://github.com/python/cpython/blob/a7dacfab8679fa605d9fb8037e5fb2753adff553/Include/internal/pycore_context.h
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/146482/{{ revealButtonHref }}
https://github.com/python/cpython/pull/146482/files#diff-eab1ba7712d90b687ef7595800ea1fbffcc4eaf34bddc447ab0fe75afd447be1
https://github.com/python/cpython/pull/146482/files#diff-eab1ba7712d90b687ef7595800ea1fbffcc4eaf34bddc447ab0fe75afd447be1
https://github.com/python/cpython/pull/146482/files#diff-eab1ba7712d90b687ef7595800ea1fbffcc4eaf34bddc447ab0fe75afd447be1
Lib/_pydecimal.pyhttps://github.com/python/cpython/pull/146482/files#diff-fad420a37a1acebb2eb47f65bf3bd7e6aedc561cc51141bd3663c0e397d41c50
View file https://github.com/python/cpython/blob/a7dacfab8679fa605d9fb8037e5fb2753adff553/Lib/_pydecimal.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/146482/{{ revealButtonHref }}
https://github.com/python/cpython/pull/146482/files#diff-fad420a37a1acebb2eb47f65bf3bd7e6aedc561cc51141bd3663c0e397d41c50
https://github.com/python/cpython/pull/146482/files#diff-fad420a37a1acebb2eb47f65bf3bd7e6aedc561cc51141bd3663c0e397d41c50
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L242
Lib/test/test_context.pyhttps://github.com/python/cpython/pull/146482/files#diff-792103db84a1a30161bf2c8d994d0fc5ee17ca7635119249ba520c96d0f238a4
View file https://github.com/python/cpython/blob/a7dacfab8679fa605d9fb8037e5fb2753adff553/Lib/test/test_context.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/146482/{{ revealButtonHref }}
https://github.com/python/cpython/pull/146482/files#diff-792103db84a1a30161bf2c8d994d0fc5ee17ca7635119249ba520c96d0f238a4
https://github.com/python/cpython/pull/146482/files#diff-792103db84a1a30161bf2c8d994d0fc5ee17ca7635119249ba520c96d0f238a4
Lib/test/test_decimal.pyhttps://github.com/python/cpython/pull/146482/files#diff-0bf3efdde952043078e322013c2459632397c6a9b312d49e70ae4a9791e2a1d8
View file https://github.com/python/cpython/blob/a7dacfab8679fa605d9fb8037e5fb2753adff553/Lib/test/test_decimal.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/146482/{{ revealButtonHref }}
https://github.com/python/cpython/pull/146482/files#diff-0bf3efdde952043078e322013c2459632397c6a9b312d49e70ae4a9791e2a1d8
https://github.com/python/cpython/pull/146482/files#diff-0bf3efdde952043078e322013c2459632397c6a9b312d49e70ae4a9791e2a1d8
Misc/NEWS.d/next/Library/2026-03-26-10-27-07.gh-issue-141148._XpYnI.rsthttps://github.com/python/cpython/pull/146482/files#diff-83cbcefa786f55deb2160941ebacb22ac1586411cfd7d827571fa1f7e2ed85d6
View file https://github.com/python/cpython/blob/a7dacfab8679fa605d9fb8037e5fb2753adff553/Misc/NEWS.d/next/Library/2026-03-26-10-27-07.gh-issue-141148._XpYnI.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/146482/{{ revealButtonHref }}
Modules/_decimal/_decimal.chttps://github.com/python/cpython/pull/146482/files#diff-071237c57ffb81dd4303eb5f02e5c5a661891a31c746c8f55a97a39659ad95d6
View file https://github.com/python/cpython/blob/a7dacfab8679fa605d9fb8037e5fb2753adff553/Modules/_decimal/_decimal.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/146482/{{ revealButtonHref }}
https://github.com/python/cpython/pull/146482/files#diff-071237c57ffb81dd4303eb5f02e5c5a661891a31c746c8f55a97a39659ad95d6
https://github.com/python/cpython/pull/146482/files#diff-071237c57ffb81dd4303eb5f02e5c5a661891a31c746c8f55a97a39659ad95d6
https://github.com/python/cpython/pull/146482/files#diff-071237c57ffb81dd4303eb5f02e5c5a661891a31c746c8f55a97a39659ad95d6
https://github.com/python/cpython/pull/146482/files#diff-071237c57ffb81dd4303eb5f02e5c5a661891a31c746c8f55a97a39659ad95d6
https://github.com/python/cpython/pull/146482/files#diff-071237c57ffb81dd4303eb5f02e5c5a661891a31c746c8f55a97a39659ad95d6
Please reload this pagehttps://github.com/python/cpython/pull/146482/files
Please reload this pagehttps://github.com/python/cpython/pull/146482/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.