René's URL Explorer Experiment


Title: GH-141148: Ensure decimal.getcontext() returns fresh copy. by nascheme · Pull Request #151953 · python/cpython · GitHub

Open Graph Title: GH-141148: Ensure decimal.getcontext() returns fresh copy. by nascheme · Pull Request #151953 · python/cpython

X Title: GH-141148: Ensure decimal.getcontext() returns fresh copy. by nascheme · Pull Request #151953 · 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. This is an alternative to GH-146482. In this PR, we add a "depth" counter to PyContext, incremented every time we copy the HAMT. Then, the decimal.Context() instance can use this to determine that getcontext() needs to copy the instance. This ensures each thread or asyncio task has it's own copy of the decimal.Context() instance. This differs from GH-146482 as follows: it avoids the potential problem of keeping context vars alive longer, via the ctx_vars_origin reference. Instead, we are just using a 64-bit integer counter here to track depth. it avoids copying decimal.Context in the case that the context is reused (entered) many times, e.g. for asyncio tasks it creates slightly more work for the _pydecimal and _decimal.c code, since it has to track the depth on its Context instance Issue: gh-141148

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/151953

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:a7d91272-f5d8-29ea-32fa-e696c689f285
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id9FC8:2052BE:EF5074:14B1317:6A53B3F4
html-safe-nonce050649176ea0339e3e620e28736de96429622a6449f5dbc5a4fa5cb7bfa49a06
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RkM4OjIwNTJCRTpFRjUwNzQ6MTRCMTMxNzo2QTUzQjNGNCIsInZpc2l0b3JfaWQiOiI1Mjc0NTgzODEyODU1MzY3NTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac1212fc3a07ad9e2c5f9a139295936ce1c669e18763b93c447d30d2b0f5368f71
hovercard-subject-tagpull_request:3915847403
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/151953/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/151953/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F151953%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%2F151953%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/151953/files
Reloadhttps://github.com/python/cpython/pull/151953/files
Reloadhttps://github.com/python/cpython/pull/151953/files
Please reload this pagehttps://github.com/python/cpython/pull/151953/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/151953/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_depthhttps://github.com/nascheme/cpython/tree/decimal_ctx_depth
Conversation 0 https://github.com/python/cpython/pull/151953
Commits 2 https://github.com/python/cpython/pull/151953/commits
Checks 52 https://github.com/python/cpython/pull/151953/checks
Files changed https://github.com/python/cpython/pull/151953/files
Please reload this pagehttps://github.com/python/cpython/pull/151953/files
GH-141148: Ensure decimal.getcontext() returns fresh copy. https://github.com/python/cpython/pull/151953/files#top
Show all changes 2 commits https://github.com/python/cpython/pull/151953/files
ed4def6 Ensure decimal.getcontext() returns fresh copy. nascheme Mar 26, 2026 https://github.com/python/cpython/pull/151953/commits/ed4def6f176623be22b4684ddb4227a1fa2fcc28
645891f Fix for Android/iOS CI test failure. nascheme Jun 22, 2026 https://github.com/python/cpython/pull/151953/commits/645891ff5483ed5bdbddb83dcaa481331bda1eb8
Clear filters https://github.com/python/cpython/pull/151953/files
Please reload this pagehttps://github.com/python/cpython/pull/151953/files
Please reload this pagehttps://github.com/python/cpython/pull/151953/files
pycore_context.h https://github.com/python/cpython/pull/151953/files#diff-eab1ba7712d90b687ef7595800ea1fbffcc4eaf34bddc447ab0fe75afd447be1
_pydecimal.py https://github.com/python/cpython/pull/151953/files#diff-fad420a37a1acebb2eb47f65bf3bd7e6aedc561cc51141bd3663c0e397d41c50
test_context.py https://github.com/python/cpython/pull/151953/files#diff-792103db84a1a30161bf2c8d994d0fc5ee17ca7635119249ba520c96d0f238a4
test_decimal.py https://github.com/python/cpython/pull/151953/files#diff-0bf3efdde952043078e322013c2459632397c6a9b312d49e70ae4a9791e2a1d8
2026-03-26-10-27-07.gh-issue-141148._XpYnI.rst https://github.com/python/cpython/pull/151953/files#diff-83cbcefa786f55deb2160941ebacb22ac1586411cfd7d827571fa1f7e2ed85d6
_decimal.c https://github.com/python/cpython/pull/151953/files#diff-071237c57ffb81dd4303eb5f02e5c5a661891a31c746c8f55a97a39659ad95d6
_contextvars.c https://github.com/python/cpython/pull/151953/files#diff-423ea0723359d0da162e01f28c419c5669bc0ab824496e2a0945207d3d91592a
context.c https://github.com/python/cpython/pull/151953/files#diff-90866884a04307bbbb14a8c99bcb5c4b96edde026113a014601b2ae38881f149
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L241
Include/internal/pycore_context.hhttps://github.com/python/cpython/pull/151953/files#diff-eab1ba7712d90b687ef7595800ea1fbffcc4eaf34bddc447ab0fe75afd447be1
View file https://github.com/python/cpython/blob/645891ff5483ed5bdbddb83dcaa481331bda1eb8/Include/internal/pycore_context.h
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/151953/{{ revealButtonHref }}
https://github.com/python/cpython/pull/151953/files#diff-eab1ba7712d90b687ef7595800ea1fbffcc4eaf34bddc447ab0fe75afd447be1
https://github.com/python/cpython/pull/151953/files#diff-eab1ba7712d90b687ef7595800ea1fbffcc4eaf34bddc447ab0fe75afd447be1
https://github.com/python/cpython/pull/151953/files#diff-eab1ba7712d90b687ef7595800ea1fbffcc4eaf34bddc447ab0fe75afd447be1
Lib/_pydecimal.pyhttps://github.com/python/cpython/pull/151953/files#diff-fad420a37a1acebb2eb47f65bf3bd7e6aedc561cc51141bd3663c0e397d41c50
View file https://github.com/python/cpython/blob/645891ff5483ed5bdbddb83dcaa481331bda1eb8/Lib/_pydecimal.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/151953/{{ revealButtonHref }}
https://github.com/python/cpython/pull/151953/files#diff-fad420a37a1acebb2eb47f65bf3bd7e6aedc561cc51141bd3663c0e397d41c50
https://github.com/python/cpython/pull/151953/files#diff-fad420a37a1acebb2eb47f65bf3bd7e6aedc561cc51141bd3663c0e397d41c50
https://github.com/python/cpython/pull/151953/files#diff-fad420a37a1acebb2eb47f65bf3bd7e6aedc561cc51141bd3663c0e397d41c50
https://github.com/python/cpython/pull/151953/files#diff-fad420a37a1acebb2eb47f65bf3bd7e6aedc561cc51141bd3663c0e397d41c50
https://github.com/python/cpython/pull/151953/files#diff-fad420a37a1acebb2eb47f65bf3bd7e6aedc561cc51141bd3663c0e397d41c50
https://github.com/python/cpython/pull/151953/files#diff-fad420a37a1acebb2eb47f65bf3bd7e6aedc561cc51141bd3663c0e397d41c50
https://github.com/python/cpython/pull/151953/files#diff-fad420a37a1acebb2eb47f65bf3bd7e6aedc561cc51141bd3663c0e397d41c50
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L242
Lib/test/test_context.pyhttps://github.com/python/cpython/pull/151953/files#diff-792103db84a1a30161bf2c8d994d0fc5ee17ca7635119249ba520c96d0f238a4
View file https://github.com/python/cpython/blob/645891ff5483ed5bdbddb83dcaa481331bda1eb8/Lib/test/test_context.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/151953/{{ revealButtonHref }}
https://github.com/python/cpython/pull/151953/files#diff-792103db84a1a30161bf2c8d994d0fc5ee17ca7635119249ba520c96d0f238a4
https://github.com/python/cpython/pull/151953/files#diff-792103db84a1a30161bf2c8d994d0fc5ee17ca7635119249ba520c96d0f238a4
Lib/test/test_decimal.pyhttps://github.com/python/cpython/pull/151953/files#diff-0bf3efdde952043078e322013c2459632397c6a9b312d49e70ae4a9791e2a1d8
View file https://github.com/python/cpython/blob/645891ff5483ed5bdbddb83dcaa481331bda1eb8/Lib/test/test_decimal.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/151953/{{ revealButtonHref }}
https://github.com/python/cpython/pull/151953/files#diff-0bf3efdde952043078e322013c2459632397c6a9b312d49e70ae4a9791e2a1d8
https://github.com/python/cpython/pull/151953/files#diff-0bf3efdde952043078e322013c2459632397c6a9b312d49e70ae4a9791e2a1d8
Misc/NEWS.d/next/Library/2026-03-26-10-27-07.gh-issue-141148._XpYnI.rsthttps://github.com/python/cpython/pull/151953/files#diff-83cbcefa786f55deb2160941ebacb22ac1586411cfd7d827571fa1f7e2ed85d6
View file https://github.com/python/cpython/blob/645891ff5483ed5bdbddb83dcaa481331bda1eb8/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/151953/{{ revealButtonHref }}
Modules/_decimal/_decimal.chttps://github.com/python/cpython/pull/151953/files#diff-071237c57ffb81dd4303eb5f02e5c5a661891a31c746c8f55a97a39659ad95d6
View file https://github.com/python/cpython/blob/645891ff5483ed5bdbddb83dcaa481331bda1eb8/Modules/_decimal/_decimal.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/151953/{{ revealButtonHref }}
https://github.com/python/cpython/pull/151953/files#diff-071237c57ffb81dd4303eb5f02e5c5a661891a31c746c8f55a97a39659ad95d6
https://github.com/python/cpython/pull/151953/files#diff-071237c57ffb81dd4303eb5f02e5c5a661891a31c746c8f55a97a39659ad95d6
https://github.com/python/cpython/pull/151953/files#diff-071237c57ffb81dd4303eb5f02e5c5a661891a31c746c8f55a97a39659ad95d6
https://github.com/python/cpython/pull/151953/files#diff-071237c57ffb81dd4303eb5f02e5c5a661891a31c746c8f55a97a39659ad95d6
https://github.com/python/cpython/pull/151953/files#diff-071237c57ffb81dd4303eb5f02e5c5a661891a31c746c8f55a97a39659ad95d6
https://github.com/python/cpython/pull/151953/files#diff-071237c57ffb81dd4303eb5f02e5c5a661891a31c746c8f55a97a39659ad95d6
https://github.com/python/cpython/pull/151953/files#diff-071237c57ffb81dd4303eb5f02e5c5a661891a31c746c8f55a97a39659ad95d6
https://github.com/python/cpython/pull/151953/files#diff-071237c57ffb81dd4303eb5f02e5c5a661891a31c746c8f55a97a39659ad95d6
https://github.com/python/cpython/pull/151953/files#diff-071237c57ffb81dd4303eb5f02e5c5a661891a31c746c8f55a97a39659ad95d6
https://github.com/python/cpython/pull/151953/files#diff-071237c57ffb81dd4303eb5f02e5c5a661891a31c746c8f55a97a39659ad95d6
https://github.com/python/cpython/pull/151953/files#diff-071237c57ffb81dd4303eb5f02e5c5a661891a31c746c8f55a97a39659ad95d6
https://github.com/python/cpython/pull/151953/files#diff-071237c57ffb81dd4303eb5f02e5c5a661891a31c746c8f55a97a39659ad95d6
Please reload this pagehttps://github.com/python/cpython/pull/151953/files
Please reload this pagehttps://github.com/python/cpython/pull/151953/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.