René's URL Explorer Experiment


Title: `_interpreters` is not thread safe on the free-threaded build · Issue #126644 · python/cpython · GitHub

Open Graph Title: `_interpreters` is not thread safe on the free-threaded build · Issue #126644 · python/cpython

X Title: `_interpreters` is not thread safe on the free-threaded build · Issue #126644 · python/cpython

Description: Crash report What happened? First off, sorry for not being able to offer code that is more reduced and certain to trigger a repro. The code below non-deterministically triggers python: Python/index_pool.c:92: heap_pop: Assertion 'heap->s...

Open Graph Description: Crash report What happened? First off, sorry for not being able to offer code that is more reduced and certain to trigger a repro. The code below non-deterministically triggers python: Python/index...

X Description: Crash report What happened? First off, sorry for not being able to offer code that is more reduced and certain to trigger a repro. The code below non-deterministically triggers python: Python/index...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`_interpreters` is not thread safe on the free-threaded build","articleBody":"# Crash report\r\n\r\n### What happened?\r\n\r\nFirst off, sorry for not being able to offer code that is more reduced and certain to trigger a repro.\r\n\r\nThe code below non-deterministically triggers `python: Python/index_pool.c:92: heap_pop: Assertion 'heap-\u003esize \u003e 0' failed.` in a free-threading build with `PYTHON_GIL=0`.\r\n\r\n```python\r\nimport _interpreters\r\nfrom threading import Thread\r\n\r\ndef f(): pass\r\n\r\nints = []\r\nfor x in range(300):\r\n    ints.append(_interpreters.create())\r\n\r\nthreads = []\r\nfor interpr in ints:\r\n    threads.append(Thread(target=_interpreters.run_string, args=(interpr, \"f()\",)))\r\n    threads.append(Thread(target=_interpreters.get_current, args=()))\r\n    threads.append(Thread(target=_interpreters.destroy, args=(interpr,)))\r\n    threads.append(Thread(target=_interpreters.list_all, args=()))\r\n    threads.append(Thread(target=_interpreters.destroy, args=(interpr,)))\r\n    threads.append(Thread(target=_interpreters.get_current, args=()))\r\n    threads.append(Thread(target=_interpreters.get_main, args=()))\r\n    threads.append(Thread(target=_interpreters.destroy, args=(interpr,)))\r\n    threads.append(Thread(target=_interpreters.run_string, args=(interpr, \"f()\",)))\r\n\r\nfor thread in threads:\r\n    try:\r\n        print(\"START\", thread)\r\n        thread.start()\r\n    except Exception:\r\n        pass\r\n\r\nfor thread in threads:\r\n    try:\r\n        print(\"JOIN\", thread)\r\n        thread.join()\r\n    except Exception:\r\n        pass\r\n```\r\n\r\nBacktrace:\r\n```gdb\r\n#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=140729519150656) at ./nptl/pthread_kill.c:44\r\n#1  __pthread_kill_internal (signo=6, threadid=140729519150656) at ./nptl/pthread_kill.c:78\r\n#2  __GI___pthread_kill (threadid=140729519150656, signo=signo@entry=6) at ./nptl/pthread_kill.c:89\r\n#3  0x00007ffff7ce0476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26\r\n#4  0x00007ffff7cc67f3 in __GI_abort () at ./stdlib/abort.c:79\r\n#5  0x00007ffff7cc671b in __assert_fail_base (fmt=0x7ffff7e7b130 \"%s%s%s:%u: %s%sAssertion `%s' failed.\\n%n\",\r\n    assertion=0x555555aceaf4 \"heap-\u003esize \u003e 0\", file=0x555555aceae0 \"Python/index_pool.c\", line=92, function=\u003coptimized out\u003e)\r\n    at ./assert/assert.c:92\r\n#6  0x00007ffff7cd7e96 in __GI___assert_fail (assertion=assertion@entry=0x555555aceaf4 \"heap-\u003esize \u003e 0\",\r\n    file=file@entry=0x555555aceae0 \"Python/index_pool.c\", line=line@entry=92,\r\n    function=function@entry=0x555555aceb40 \u003c__PRETTY_FUNCTION__.1\u003e \"heap_pop\") at ./assert/assert.c:101\r\n#7  0x00005555558caa1c in heap_pop (heap=\u003coptimized out\u003e) at Python/index_pool.c:92\r\n#8  0x00005555558cac33 in _PyIndexPool_AllocIndex (pool=pool@entry=0x7ffff780f498) at Python/index_pool.c:173\r\n#9  0x000055555568d9f0 in _Py_ReserveTLBCIndex (interp=interp@entry=0x7ffff780b020) at Objects/codeobject.c:2752\r\n#10 0x0000555555951c33 in new_threadstate (interp=interp@entry=0x7ffff780b020, whence=whence@entry=5) at Python/pystate.c:1516\r\n#11 0x0000555555953994 in _PyThreadState_NewBound (interp=interp@entry=0x7ffff780b020, whence=whence@entry=5)\r\n    at Python/pystate.c:1578\r\n#12 0x0000555555896ee9 in _enter_session (session=session@entry=0x7ffe24ff8740, interp=interp@entry=0x7ffff780b020)\r\n    at Python/crossinterp.c:1548\r\n#13 0x000055555589b9fb in _PyXI_Enter (session=session@entry=0x7ffe24ff8740, interp=interp@entry=0x7ffff780b020,\r\n    nsupdates=nsupdates@entry=0x0) at Python/crossinterp.c:1711\r\n#14 0x00007ffff7c3d217 in _run_in_interpreter (interp=interp@entry=0x7ffff780b020, codestr=0x200006182c8 \"f()\", codestrlen=3,\r\n    shareables=shareables@entry=0x0, flags=1, p_excinfo=p_excinfo@entry=0x7ffe24ff8870) at ./Modules/_interpretersmodule.c:461\r\n#15 0x00007ffff7c3d3ef in _interp_exec (self=self@entry=\u003cmodule at remote 0x20000778b30\u003e, interp=interp@entry=0x7ffff780b020,\r\n    code_arg=\u003coptimized out\u003e, shared_arg=0x0, p_excinfo=p_excinfo@entry=0x7ffe24ff8870) at ./Modules/_interpretersmodule.c:950\r\n#16 0x00007ffff7c3dc6b in interp_run_string (self=\u003cmodule at remote 0x20000778b30\u003e, args=args@entry=(9, 'f()'), kwds=kwds@entry={})\r\n    at ./Modules/_interpretersmodule.c:1110\r\n#17 0x000055555570145a in cfunction_call (func=func@entry=\u003cbuilt-in method run_string of module object at remote 0x20000778b30\u003e,\r\n    args=args@entry=(9, 'f()'), kwargs=kwargs@entry={}) at Objects/methodobject.c:551\r\n#18 0x000055555567f69a in _PyObject_Call (tstate=0x5555560c09d0,\r\n    callable=callable@entry=\u003cbuilt-in method run_string of module object at remote 0x20000778b30\u003e, args=args@entry=(9, 'f()'),\r\n    kwargs=kwargs@entry={}) at Objects/call.c:361\r\n```\r\n\r\nThis code most usually results in one of the following errors, from most common to rarest:\r\n\r\n1. tstate_delete_common assertion, which seems to indicate a thread creation failed, see https://github.com/python/cpython/issues/109746.\r\n```\r\npython: Python/pystate.c:1739: tstate_delete_common: Assertion `tstate-\u003e_status.cleared \u0026\u0026 !tstate-\u003e_status.finalized' failed.\r\n```\r\n\r\n2. Fatal Python error, seems to be https://github.com/python/cpython/issues/113148.\r\n\r\n```\r\nFatal Python error: Py_EndInterpreter: not the last thread\r\nPython runtime state: initialized\r\n\r\nCurrent thread 0x00007f09af37e640 (most recent call first):\r\n  \u003cno Python frame\u003e\r\n\r\nThread 0x00007f09b0380640 (most recent call first):\r\n  \u003cno Python frame\u003e\r\nAborted\r\n```\r\n\r\nGiven that, running it multiple times seems necessary to trigger the correct abort in `heap_pop`. The affected code seems to have been included in https://github.com/python/cpython/pull/123926, so cc @mpage.\r\n\r\nFound using fusil by @vstinner.\r\n\r\n### CPython versions tested on:\r\n\r\nCPython main branch\r\n\r\n### Operating systems tested on:\r\n\r\nLinux\r\n\r\n### Output from running 'python -VV' on the command line:\r\n\r\nPython 3.14.0a1+ experimental free-threading build (heads/main-dirty:54c63a32d0, Nov  8 2024, 20:16:36) [GCC 11.4.0]\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-126696\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/devdanzin","@type":"Person","name":"devdanzin"},"datePublished":"2024-11-10T15:09:04.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/126644/cpython/issues/126644"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:27899ed5-80a6-c8a6-d85c-246ad1a12765
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE50E:9B0A:22410C8:3194AA9:6A565B87
html-safe-nonce33a71c9ce9684cf0fd109615dd4bec0a491f9f81e6b3a4f6d58b5e15c2bfcec0
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNTBFOjlCMEE6MjI0MTBDODozMTk0QUE5OjZBNTY1Qjg3IiwidmlzaXRvcl9pZCI6IjI5MTE3NzkwMjg2MzY5NDkzODMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac4666a158a9926229afaea544d5d4e1f0af10d38198cbb5bfc49ae24bb9ecc99d
hovercard-subject-tagissue:2647328879
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/126644/issue_layout
twitter:imagehttps://opengraph.githubassets.com/9bb8075225d689298b73c00d2fff72976f78566e39835e053f2b1bc22e7996ba/python/cpython/issues/126644
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/9bb8075225d689298b73c00d2fff72976f78566e39835e053f2b1bc22e7996ba/python/cpython/issues/126644
og:image:altCrash report What happened? First off, sorry for not being able to offer code that is more reduced and certain to trigger a repro. The code below non-deterministically triggers python: Python/index...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamedevdanzin
hostnamegithub.com
expected-hostnamegithub.com
None6a3afe34dff341ad10912db44becf282289d7f2af20576241738530fbb28de01
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
releaseb71002134df95575e9f6c2945a64d454b0be181e
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/126644#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F126644
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%2Fissues%2F126644
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/126644
Reloadhttps://github.com/python/cpython/issues/126644
Reloadhttps://github.com/python/cpython/issues/126644
Please reload this pagehttps://github.com/python/cpython/issues/126644
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/126644
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
_interpreters is not thread safe on the free-threaded buildhttps://github.com/python/cpython/issues/126644#top
https://github.com/ZeroIntensity
3.13bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.13%22
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
topic-subinterpretershttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-subinterpreters%22
type-crashA hard crash of the interpreter, possibly with a core dumphttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-crash%22
https://github.com/devdanzin
devdanzinhttps://github.com/devdanzin
on Nov 10, 2024https://github.com/python/cpython/issues/126644#issue-2647328879
Crash at finalization after fail to start new thread #109746https://github.com/python/cpython/issues/109746
Crash Due to Exception in threading._shutdown() #113148https://github.com/python/cpython/issues/113148
#123926https://github.com/python/cpython/pull/123926
@mpagehttps://github.com/mpage
@vstinnerhttps://github.com/vstinner
gh-126644: Fix various thread safety issues in _interpreters #126696https://github.com/python/cpython/pull/126696
ZeroIntensityhttps://github.com/ZeroIntensity
3.13bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.13%22
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
topic-subinterpretershttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-subinterpreters%22
type-crashA hard crash of the interpreter, possibly with a core dumphttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-crash%22
Subinterpretershttps://github.com/orgs/python/projects/3
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.