René's URL Explorer Experiment


Title: Under-estimated stack size for recursion limit (macOS + python >= 3.14) · Issue #139231 · python/cpython · GitHub

Open Graph Title: Under-estimated stack size for recursion limit (macOS + python >= 3.14) · Issue #139231 · python/cpython

X Title: Under-estimated stack size for recursion limit (macOS + python >= 3.14) · Issue #139231 · python/cpython

Description: Bug report Bug description: GH-130398 introduced estimation of stack size (for the purpose of recursion-limit management) via pthread_getattr_np() on platforms that support it. This non-portable function is not available on macOS, and so...

Open Graph Description: Bug report Bug description: GH-130398 introduced estimation of stack size (for the purpose of recursion-limit management) via pthread_getattr_np() on platforms that support it. This non-portable fu...

X Description: Bug report Bug description: GH-130398 introduced estimation of stack size (for the purpose of recursion-limit management) via pthread_getattr_np() on platforms that support it. This non-portable fu...

Opengraph URL: https://github.com/python/cpython/issues/139231

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Under-estimated stack size for recursion limit (macOS + python \u003e= 3.14)","articleBody":"# Bug report\n\n### Bug description:\n\nGH-130398 introduced estimation of stack size (for the purpose of recursion-limit management) via `pthread_getattr_np()` on platforms that support it. This non-portable function is not available on macOS, and so the following fallback codepath is used:\n\nhttps://github.com/python/cpython/blob/4fb338d844a1e992857a17b5bd1269837e847fb2/Python/ceval.c#L485-L487\n\nwith `Py_C_STACK_SIZE` being set to 4 MB on macOS:\n\nhttps://github.com/python/cpython/blob/4fb338d844a1e992857a17b5bd1269837e847fb2/Python/ceval.c#L369-L381\n\nHowever, this is too conservative, as the python's build script explicitly increases the stack to 16 MB:\n\nhttps://github.com/python/cpython/blob/4fb338d844a1e992857a17b5bd1269837e847fb2/configure.ac#L3601-L3628\n\nThis was observed in GH-131543, but was not investigated further, because the primary issue there turned out to be excessive stack consumption due to inlining (GH-137573).\n\nNevertheless, the under-estimated stack size still negatively impacts the recursion limit.\n\nUsing slightly modified reproducer from https://github.com/python/cpython/issues/131543#issuecomment-2907899988 that keeps trying to dynamically increase recursion limit as it keeps recursing:\n\n```c\n// stackpointer.c\n//\n// gcc -shared -fpic -o stackpointer.dylib stackpointer.c\n//\n// import ctypes\n// sp = ctypes.CDLL('./stackpointer.dylib')\n// address = sp.get_machine_stack_pointer()\n\n#include \u003cstdint.h\u003e\n\nuintptr_t get_machine_stack_pointer(void)\n{\n    return (uintptr_t)__builtin_frame_address(0);\n}\n```\n\n```python\n# recursion_limit_test.py\nimport sys\nimport ctypes\nimport ctypes.util\n\n# Obtain stack address and stack size as reported by non-portable pthread functions:\nlibc = ctypes.CDLL(ctypes.util.find_library('c'))\n\nlibc.pthread_self.restype = ctypes.c_void_p\n\nlibc.pthread_get_stackaddr_np.argtypes = [ctypes.c_void_p]\nlibc.pthread_get_stackaddr_np.restype = ctypes.c_void_p\n\nlibc.pthread_get_stacksize_np.argtypes = [ctypes.c_void_p]\nlibc.pthread_get_stacksize_np.restype = ctypes.c_ulonglong\n\nthis_thread = libc.pthread_self()\n\nstack_address = libc.pthread_get_stackaddr_np(this_thread)\nstack_size = libc.pthread_get_stacksize_np(this_thread)\n\nprint(f\"Stack address: {stack_address} = 0x{stack_address:X}\")\nprint(f\"Stack size: {stack_size} = {stack_size / 1024.0} kB = {stack_size / 1024**2} MB\")\n\n# Helper for tracking stack pointer location\nsplib = ctypes.CDLL('./stackpointer.dylib')\nsplib.get_machine_stack_pointer.restype = ctypes.c_void_p\nstack_pointer = splib.get_machine_stack_pointer()\nprint(f\"Stack pointer: 0x{stack_pointer:X}, depth: {(stack_address - stack_pointer)/1024:.2f} kB\")\n\n# Recursion limit test\nlimit = sys.getrecursionlimit()\ncounter = 0\n\nclass A:\n    def __getattribute__(self, name):\n        global counter\n        counter += 1\n        stack_pointer = splib.get_machine_stack_pointer()\n        print(f\"Recursion level: {counter}, stack pointer: 0x{stack_pointer:X}, depth: {(stack_address - stack_pointer)/1024:.2f} kB\")\n\n        # Increase recursion limit, if necessary\n        global limit\n        if counter + 1 \u003e= limit:\n            limit *= 2\n            print(f\"Increasing recursion limit: {limit}\")\n            sys.setrecursionlimit(limit)\n\n        # Recurse\n        return getattr(self, name)\n\n\na = A()\nprint(\"Testing Recursion Limit\")\nprint(f\"Initial limit: {limit}\")\ntry:\n    a.test\nexcept RecursionError:\n    print(f\"Recursion Limit ok (reached level {counter})\")\n``` \n\n----\nRunning with python 3.13:\n\n```\n% python3.13 recursion_limit_test.py\nStack address: 6101024768 = 0x16BA64000\nStack size: 16777216 = 16384.0 kB = 16.0 MB\nStack pointer: 0x16BA622A0, depth: 7.34 kB\nTesting Recursion Limit\nInitial limit: 1000\nRecursion level: 1, stack pointer: 0x16BA61CD0, depth: 8.80 kB\nRecursion level: 2, stack pointer: 0x16BA616A0, depth: 10.34 kB\nRecursion level: 3, stack pointer: 0x16BA610B0, depth: 11.83 kB\n...\nRecursion level: 4997, stack pointer: 0x16B323CD0, depth: 7424.80 kB\nRecursion level: 4998, stack pointer: 0x16B3236E0, depth: 7426.28 kB\nRecursion Limit ok (reached level 4999)\n```\n\nNote that even with the old approach, only about half of the actual 16 MB stack was used before the recursion limit kicked in  (as evident from estimated stack depth).\n\n---\nWith 3.14(.0rc2):\n\n```\n% python3.14 recursion_limit_test.py\nStack address: 6091063296 = 0x16B0E4000\nStack size: 16777216 = 16384.0 kB = 16.0 MB\nStack pointer: 0x16B0E1CC0, depth: 8.81 kB\nTesting Recursion Limit\nInitial limit: 1000\nRecursion level: 1, stack pointer: 0x16B0E1120, depth: 11.72 kB\nRecursion level: 2, stack pointer: 0x16B0E0550, depth: 14.67 kB\n...\nRecursion level: 1320, stack pointer: 0x16AD13470, depth: 3906.89 kB\nRecursion level: 1321, stack pointer: 0x16AD128A0, depth: 3909.84 kB\nRecursion Limit ok (reached level 1322)\n``` \n\nWith 3.14, we don't get far above the original limit before the recursion limit kicks in, under assumption of 4 MB stack.\n\n### CPython versions tested on:\n\n3.14\n\n### Operating systems tested on:\n\nmacOS\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-139232\n* gh-139290\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/rokm","@type":"Person","name":"rokm"},"datePublished":"2025-09-22T12:15:50.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/139231/cpython/issues/139231"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:d90146a3-290b-789d-d1b5-8b0c457af530
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idB3A8:139CD4:54FA56:70C7D0:696B4202
html-safe-nonce071507b8fd2aa9b8f9ff2c45ccc5bdacbd19e49887c9d865f74cadaba7396399
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCM0E4OjEzOUNENDo1NEZBNTY6NzBDN0QwOjY5NkI0MjAyIiwidmlzaXRvcl9pZCI6IjE0MjI0NjQyNjUwNzM5MzQ4NTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac47d63273c24b9309512279f55a9820d33a85354e7acc7b725bff60852fba202d
hovercard-subject-tagissue:3440679303
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/139231/issue_layout
twitter:imagehttps://opengraph.githubassets.com/03d11ea5d38babc98b7ddf3e28682b3b3f4226f4e2cbbd48445aaa3ac55f3bf4/python/cpython/issues/139231
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/03d11ea5d38babc98b7ddf3e28682b3b3f4226f4e2cbbd48445aaa3ac55f3bf4/python/cpython/issues/139231
og:image:altBug report Bug description: GH-130398 introduced estimation of stack size (for the purpose of recursion-limit management) via pthread_getattr_np() on platforms that support it. This non-portable fu...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamerokm
hostnamegithub.com
expected-hostnamegithub.com
None5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d
turbo-cache-controlno-preview
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
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release82560a55c6b2054555076f46e683151ee28a19bc
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/139231#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F139231
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
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
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
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/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%2Fissues%2F139231
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%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/139231
Reloadhttps://github.com/python/cpython/issues/139231
Reloadhttps://github.com/python/cpython/issues/139231
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/139231
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k 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.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/issues/139231
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 https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/139231
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/139231
#139232https://github.com/python/cpython/pull/139232
Under-estimated stack size for recursion limit (macOS + python >= 3.14)https://github.com/python/cpython/issues/139231#top
#139232https://github.com/python/cpython/pull/139232
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15new features, bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
OS-machttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22OS-mac%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/rokm
https://github.com/rokm
rokmhttps://github.com/rokm
on Sep 22, 2025https://github.com/python/cpython/issues/139231#issue-3440679303
GH-130398https://github.com/python/cpython/pull/130398
cpython/Python/ceval.chttps://github.com/python/cpython/blob/4fb338d844a1e992857a17b5bd1269837e847fb2/Python/ceval.c#L485-L487
4fb338dhttps://github.com/python/cpython/commit/4fb338d844a1e992857a17b5bd1269837e847fb2
cpython/Python/ceval.chttps://github.com/python/cpython/blob/4fb338d844a1e992857a17b5bd1269837e847fb2/Python/ceval.c#L369-L381
4fb338dhttps://github.com/python/cpython/commit/4fb338d844a1e992857a17b5bd1269837e847fb2
cpython/configure.achttps://github.com/python/cpython/blob/4fb338d844a1e992857a17b5bd1269837e847fb2/configure.ac#L3601-L3628
4fb338dhttps://github.com/python/cpython/commit/4fb338d844a1e992857a17b5bd1269837e847fb2
GH-131543https://github.com/python/cpython/issues/131543
GH-137573https://github.com/python/cpython/issues/137573
#131543 (comment)https://github.com/python/cpython/issues/131543#issuecomment-2907899988
gh-139231: Fix estimation of available stack size for recursion limit on macOS #139232https://github.com/python/cpython/pull/139232
[3.14] gh-139231: Fix estimation of available stack size for recursion limit on macOS (GH-139232) #139290https://github.com/python/cpython/pull/139290
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15new features, bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
OS-machttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22OS-mac%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
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.