René's URL Explorer Experiment


Title: Legacy-mode subinterpreters in Python 3.12: `import _tkinter` leads to shutdown crash · Issue #115649 · python/cpython · GitHub

Open Graph Title: Legacy-mode subinterpreters in Python 3.12: `import _tkinter` leads to shutdown crash · Issue #115649 · python/cpython

X Title: Legacy-mode subinterpreters in Python 3.12: `import _tkinter` leads to shutdown crash · Issue #115649 · python/cpython

Description: Bug report Bug description: Hello everyone, I am working on an application embedding multiple Python subinterpreters - for which the Python version should be upgraded from Python 3.10 to Python 3.12.1. For the time being, the "legacy ver...

Open Graph Description: Bug report Bug description: Hello everyone, I am working on an application embedding multiple Python subinterpreters - for which the Python version should be upgraded from Python 3.10 to Python 3.1...

X Description: Bug report Bug description: Hello everyone, I am working on an application embedding multiple Python subinterpreters - for which the Python version should be upgraded from Python 3.10 to Python 3.1...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Legacy-mode subinterpreters in Python 3.12: `import _tkinter` leads to shutdown crash ","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\nHello everyone,\r\n\r\nI am working on an application embedding multiple Python subinterpreters - for which the Python version should be upgraded from Python 3.10 to Python 3.12.1. For the time being, the \"legacy version\" of subinterpreters (i.e., using a global, shared GIL) should be used, since all Python extensions (including `_tkinter` and all extensions with single-phase initialization) should be supported.\r\n\r\nIf I understand the docs correctly, using the legacy `Py_NewInterpreter()` method should preserve the existing behavior. Still, the following application crashes at shutdown:\r\n\r\n```c++\r\n#include \u003cPython.h\u003e\r\n\r\nclass PythonInterpreter {\r\n public:\r\n    PythonInterpreter(PyThreadState* parent, int id)\r\n    : mParent(parent)\r\n    , mId(id) {\r\n        PyEval_RestoreThread(mParent);\r\n        mThread = Py_NewInterpreter();\r\n        PyObject* globals = PyModule_GetDict(PyImport_AddModule(\"__main__\"));\r\n        PyRun_String(\"import _tkinter\", Py_single_input, globals, globals);\r\n        PyEval_SaveThread();\r\n        std::cout \u003c\u003c \"Subinterpreter \" \u003c\u003c id \u003c\u003c \" done\" \u003c\u003c std::endl;\r\n    }\r\n\r\n    virtual ~PythonInterpreter() {\r\n        std::cout \u003c\u003c \"destructor \" \u003c\u003c mId \u003c\u003c std::endl;\r\n        PyThreadState_Swap(mThread);\r\n        Py_EndInterpreter(mThread);\r\n    }\r\n\r\n private:\r\n    PyThreadState* mParent;\r\n    PyThreadState* mThread;\r\n    int mId;\r\n};\r\n\r\nint main(int /* argc */, char** /* argv[] */) {\r\n    PyConfig config;\r\n    PyConfig_InitPythonConfig(\u0026config);\r\n    PyStatus status = Py_InitializeFromConfig(\u0026config);\r\n    if (PyStatus_Exception(status)) {\r\n        PyConfig_Clear(\u0026config);\r\n        Py_ExitStatusException(status);\r\n    } else {\r\n        PyConfig_Clear(\u0026config);\r\n    }\r\n    PyThreadState* s0 = PyThreadState_Get();\r\n    PyEval_SaveThread();\r\n    PythonInterpreter* i0 = new PythonInterpreter(s0, 0);\r\n    PythonInterpreter* i1 = new PythonInterpreter(s0, 1);\r\n    delete i0;\r\n    delete i1;\r\n    PyEval_RestoreThread(s0);\r\n    Py_Finalize();\r\n}\r\n```\r\n\r\nWhen compiling and running this program with a debug build of Python 3.12.1 (or later) on Linux, I get this output:\r\n\r\n```\r\nSubinterpreter 0 done\r\nSubinterpreter 1 done\r\ndestructor 0\r\ndestructor 1\r\nmain: Objects/dictobject.c:283: unicode_get_hash: Assertion `Py_IS_TYPE(((PyObject*)(((o)))), (\u0026PyUnicode_Type))' failed.\r\n```\r\n\r\nWith a non-debug build, the program exits with a segmentation fault.\r\n\r\nThe `gdb` backtrace looks as follows:\r\n\r\n```\r\n#0  0x00007ffff6311387 in raise () from /lib64/libc.so.6\r\n#1  0x00007ffff6312a78 in abort () from /lib64/libc.so.6\r\n#2  0x00007ffff630a1a6 in __assert_fail_base () from /lib64/libc.so.6\r\n#3  0x00007ffff630a252 in __assert_fail () from /lib64/libc.so.6\r\n#4  0x00007ffff6a9baf5 in unicode_get_hash (o=\u003coptimized out\u003e) at Objects/dictobject.c:2143\r\n#5  _PyDict_Next (op=op@entry=0x7fffecfd2270, ppos=ppos@entry=0x7fffffffd2a8, pkey=pkey@entry=0x7fffffffd2a0, pvalue=pvalue@entry=0x7fffffffd298, \r\n    phash=phash@entry=0x0) at Objects/dictobject.c:2142\r\n#6  0x00007ffff6a9c0d8 in PyDict_Next (op=op@entry=0x7fffecfd2270, ppos=ppos@entry=0x7fffffffd2a8, pkey=pkey@entry=0x7fffffffd2a0, \r\n    pvalue=pvalue@entry=0x7fffffffd298) at Objects/dictobject.c:2189\r\n#7  0x00007ffff6ab3751 in _PyModule_ClearDict (d=0x7fffecfd2270) at Objects/moduleobject.c:624\r\n#8  0x00007ffff6ab40dd in _PyModule_Clear (m=m@entry=0x7fffed02ca70) at Objects/moduleobject.c:604\r\n#9  0x00007ffff6c11bd4 in finalize_modules_clear_weaklist (interp=interp@entry=0x7fffed03c020, weaklist=weaklist@entry=0x7fffef912da0, verbose=verbose@entry=0)\r\n    at Python/pylifecycle.c:1526\r\n#10 0x00007ffff6c125ef in finalize_modules (tstate=tstate@entry=0x7fffed099950) at Python/pylifecycle.c:1609\r\n#11 0x00007ffff6c202da in Py_EndInterpreter (tstate=0x7fffed099950) at Python/pylifecycle.c:2220\r\n#12 0x00000000004014b5 in PythonInterpreter::~PythonInterpreter (this=0x5092f0, __in_chrg=\u003coptimized out\u003e) at main.cc:25\r\n#13 PythonInterpreter::~PythonInterpreter (this=0x5092f0, __in_chrg=\u003coptimized out\u003e) at main.cc:26\r\n#14 0x00000000004012e2 in main () at main.cc:60\r\n```\r\n\r\nDigging further into the backtrace, it looks like the Python garbage collector is trying to decrease the reference counter to the `_tkinter` module twice, despite it having been increased only once. Oddly enough, the program runs just fine when destroying the interpreters in reverse order:\r\n\r\n```c++\r\n    PythonInterpreter* i0 = new PythonInterpreter(s0, 0);\r\n    PythonInterpreter* i1 = new PythonInterpreter(s0, 1);\r\n    delete i1;\r\n    delete i0;\r\n```\r\n\r\nCan anyone help me shed some light into this issue? Is there anything I am overlooking?\r\n\r\n### CPython versions tested on:\r\n\r\n3.12.1, 3.12.2, 3.13.0a4\r\n\r\n### Operating systems tested on:\r\n\r\nLinux, Windows\n```[tasklist]\n### Tasks\n```\n\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-120290\n* gh-120315\n* gh-120652\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/car-bianco","@type":"Person","name":"car-bianco"},"datePublished":"2024-02-19T11:22:04.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/115649/cpython/issues/115649"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:ed4c961d-bbe6-cd1f-b9ef-4fbf3be5924b
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA2F6:37A6A7:93110:D1295:696A4448
html-safe-nonce7c1b84c0d02ef822de432e344b0c51b2c677c634f19174f27e84d307969d8a79
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMkY2OjM3QTZBNzo5MzExMDpEMTI5NTo2OTZBNDQ0OCIsInZpc2l0b3JfaWQiOiI1Nzc3NzIzMDk2NDk5MzczMTI4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmaca81949a1b1f104dba3977c88244a2926b3abe53f05d46ac1466bacab3966f9ed
hovercard-subject-tagissue:2142139652
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/115649/issue_layout
twitter:imagehttps://opengraph.githubassets.com/41b4489ea3600cbe1cd1979a38642258552f5bb29b96d53f8f5e8fba5314cf06/python/cpython/issues/115649
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/41b4489ea3600cbe1cd1979a38642258552f5bb29b96d53f8f5e8fba5314cf06/python/cpython/issues/115649
og:image:altBug report Bug description: Hello everyone, I am working on an application embedding multiple Python subinterpreters - for which the Python version should be upgraded from Python 3.10 to Python 3.1...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamecar-bianco
hostnamegithub.com
expected-hostnamegithub.com
None3f871c8e07f0ae1886fa8dac284166d28b09ad5bada6476fc10b674e489788ef
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
release63c426b30d262aba269ef14c40e3c817b384cd61
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/115649#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F115649
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%2F115649
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/115649
Reloadhttps://github.com/python/cpython/issues/115649
Reloadhttps://github.com/python/cpython/issues/115649
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/115649
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/115649
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/115649
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/115649
Legacy-mode subinterpreters in Python 3.12: import _tkinter leads to shutdown crash https://github.com/python/cpython/issues/115649#top
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/car-bianco
https://github.com/car-bianco
car-biancohttps://github.com/car-bianco
on Feb 19, 2024https://github.com/python/cpython/issues/115649#issue-2142139652
gh-115649: Fix double free for intern strings dict #120290https://github.com/python/cpython/pull/120290
gh-115649: Copy the filename into main interpreter before intern in import.c #120315https://github.com/python/cpython/pull/120315
[3.13] gh-115649: Copy the filename into main interpreter before intern in import.c (GH-120315) #120652https://github.com/python/cpython/pull/120652
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.