René's URL Explorer Experiment


Title: 3.12: "Python memory allocator called without holding the GIL" with `PyMem_Free` as `Py_AtExit` · Issue #105690 · python/cpython · GitHub

Open Graph Title: 3.12: "Python memory allocator called without holding the GIL" with `PyMem_Free` as `Py_AtExit` · Issue #105690 · python/cpython

X Title: 3.12: "Python memory allocator called without holding the GIL" with `PyMem_Free` as `Py_AtExit` · Issue #105690 · python/cpython

Description: When importing PyQt6 with Python 3.12.0b2 (as well as on the current git 3.12, 0b305e8), it segfaults on exit. Program received signal SIGSEGV, Segmentation fault. 0x000055555572563a in _PyInterpreterState_GET () at ./Include/internal/py...

Open Graph Description: When importing PyQt6 with Python 3.12.0b2 (as well as on the current git 3.12, 0b305e8), it segfaults on exit. Program received signal SIGSEGV, Segmentation fault. 0x000055555572563a in _PyInterpre...

X Description: When importing PyQt6 with Python 3.12.0b2 (as well as on the current git 3.12, 0b305e8), it segfaults on exit. Program received signal SIGSEGV, Segmentation fault. 0x000055555572563a in _PyInterpre...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"3.12: \"Python memory allocator called without holding the GIL\" with `PyMem_Free` as `Py_AtExit`","articleBody":"When importing PyQt6 with Python 3.12.0b2 (as well as on the current git 3.12, 0b305e8d36c5ac5dc83f0c09e7e2b3360b992eea), it segfaults on exit.\r\n\r\n```c\r\nProgram received signal SIGSEGV, Segmentation fault.\r\n0x000055555572563a in _PyInterpreterState_GET () at ./Include/internal/pycore_pystate.h:126\r\n126\t   return tstate-\u003einterp;\r\n(gdb) bt\r\n#0  0x000055555572563a in _PyInterpreterState_GET () at ./Include/internal/pycore_pystate.h:126\r\n#1  get_state () at Objects/obmalloc.c:866\r\n#2  _PyObject_Free (ctx=\u003coptimized out\u003e, p=0x555555d527a0) at Objects/obmalloc.c:1850\r\n#3  _PyObject_Free (ctx=0x0, p=0x555555d527a0) at Objects/obmalloc.c:1843\r\n#4  0x00007ffff75e5351 in finalise () at sip_core.c:1807\r\n#5  0x0000555555835235 in call_ll_exitfuncs (runtime=0x555555ba6380 \u003c_PyRuntime\u003e) at Python/pylifecycle.c:3002\r\n#6  Py_FinalizeEx () at Python/pylifecycle.c:1966\r\n#7  0x0000555555838075 in Py_FinalizeEx () at Python/pylifecycle.c:1970\r\n#8  0x00005555558693cf in Py_RunMain () at Modules/main.c:691\r\n[...]\r\n```\r\n\r\nA `--with-pydebug` build instead prints:\r\n\r\n```\r\nFatal Python error: _PyMem_DebugFree: Python memory allocator called without holding the GIL                                                                                                                                                  \r\nPython runtime state: finalizing (tstate=0x0000555555c76490)\r\n```\r\n\r\nand aborts in:\r\n\r\n```c\r\n[...]\r\n#4  0x0000555555847cc2 in fatal_error_exit (status=\u003coptimized out\u003e) at Python/pylifecycle.c:2693\r\n#5  0x000055555584957c in fatal_error (fd=2, header=header@entry=1, prefix=prefix@entry=0x55555591fa10 \u003c__func__.3\u003e \"_PyMem_DebugFree\", msg=msg@entry=0x5555559202d8 \"Python memory allocator called without holding the GIL\", \r\n    status=status@entry=-1) at Python/pylifecycle.c:2874\r\n#6  0x00005555558495e6 in _Py_FatalErrorFunc (func=func@entry=0x55555591fa10 \u003c__func__.3\u003e \"_PyMem_DebugFree\", msg=msg@entry=0x5555559202d8 \"Python memory allocator called without holding the GIL\") at Python/pylifecycle.c:2890\r\n#7  0x000055555573f9b3 in _PyMem_DebugCheckGIL (func=func@entry=0x55555591fa10 \u003c__func__.3\u003e \"_PyMem_DebugFree\") at Objects/obmalloc.c:2271\r\n#8  0x000055555573fa30 in _PyMem_DebugFree (ctx=0x555555c024d0 \u003c_PyRuntime+208\u003e, ptr=0x555555dd67b0) at Objects/obmalloc.c:2295\r\n#9  0x00005555557408e7 in PyMem_Free (ptr=\u003coptimized out\u003e) at Objects/obmalloc.c:732\r\n#10 0x00007ffff74e5296 in sip_api_free (mem=\u003coptimized out\u003e) at sip_core.c:1905\r\n#11 0x00007ffff74f529a in sipOMFinalise (om=om@entry=0x7ffff74ff820 \u003ccppPyMap\u003e) at sip_object_map.c:69\r\n#12 0x00007ffff74e5351 in finalise () at sip_core.c:1807\r\n#13 0x00005555558479d0 in call_ll_exitfuncs (runtime=runtime@entry=0x555555c02400 \u003c_PyRuntime\u003e) at Python/pylifecycle.c:3002\r\n#14 0x0000555555849153 in Py_FinalizeEx () at Python/pylifecycle.c:1966\r\n#15 0x0000555555875aa7 in Py_RunMain () at Modules/main.c:691\r\n[...]\r\n```\r\n\r\nTo reproduce, `pip install PyQt6` followed by e.g. `python3 -c \"import PyQt6.QtCore\"`.\r\n\r\n---\r\n\r\nIt's unclear to me whether this is an intended/expected regression or not, given that the behavior of `sip` (the C++ bindings behind PyQt) seems somewhat unkosher here. Its [maintainer says](https://www.riverbankcomputing.com/pipermail/pyqt/2023-June/045332.html):\r\n\r\n\u003e `finalise()` is registered with `Py_AtExit()` so that it is called by `Py_FinalizeEx()`...\r\n\u003e \r\n\u003e https://docs.python.org/3/c-api/sys.html#c.Py_AtExit\r\n\u003e \r\n\u003e The docs say nothing about the state of the GIL when a cleanup function is called. The docs also state that the cleanup handler should not make calls to the Python API, so I suppose the state of the GIL shouldn't matter.\r\n\u003e \r\n\u003e However `finalise()` does make calls to the Python API - but only to free memory (one of the stated purposes of `Py_FinalizeEx()`). It seems a little bit contradictory to me to disallow cleanup functions calling `Py_MemFree()`.\r\n\u003e \r\n\u003e If this new behaviour were to remain then sip would have to stop using the Python memory allocator and just use `malloc()` and `free()`.\r\n\r\nSo from what I understand, it sounds like this was \"if it breaks, you got to keep both pieces\" territory to begin with?\r\n\r\nHowever, I was able to bisect this to https://github.com/python/cpython/commit/6036c3e856f033bf13e929536e7bf127fdd921c9 as part of #101161 (\"Clarify GILState-related Code\"), which in the commit message claims to be a refactor only:\r\n\r\n\u003e The objective of this change is to help make the GILState-related code easier to understand.  This mostly involves moving code around and some semantically equivalent refactors.  However, there are a also a small number of slight changes in structure and behavior:\r\n\u003e \r\n\u003e * tstate_current is moved out of _PyRuntimeState.gilstate\r\n\u003e * autoTSSkey is moved out of _PyRuntimeState.gilstate\r\n\u003e * autoTSSkey is initialized earlier\r\n\u003e * autoTSSkey is re-initialized (after fork) earlier\r\n\r\nThus, I'm erring on the side of caution here, and decided to open an issue anyways - if this is something sip definitely shouldn't be doing that way, feel free to close!\r\n\r\nThe relevant sip sources can be found [on their Mercurial server](https://www.riverbankcomputing.com/hg/sip/file/tip/sipbuild/module/source/13) or in the PyPI sdist (`sipbuild/module/source/13/`). \r\n\r\ncc @philthompson10 @ericsnowcurrently ","author":{"url":"https://github.com/The-Compiler","@type":"Person","name":"The-Compiler"},"datePublished":"2023-06-12T13:08:50.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/105690/cpython/issues/105690"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:8fc5ac9a-888d-dc49-cb40-b399b58d7d2a
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCED2:2AD212:E6090:13977E:696A9AB1
html-safe-nonce29cad170eb0f86571bef429657896f5150f5232dca77844f0816a8025f2b2a0a
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRUQyOjJBRDIxMjpFNjA5MDoxMzk3N0U6Njk2QTlBQjEiLCJ2aXNpdG9yX2lkIjoiNDM0Mzc5MDIzNTQyNjY1ODk5MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac293cb74d5b2d6377262ea9b11e24c3bd7ad027b04a2e7dd1342668f10d4c2437
hovercard-subject-tagissue:1752736136
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/105690/issue_layout
twitter:imagehttps://opengraph.githubassets.com/162ef70a9efd51363d444fe60ccb44c20a5807ac76d2d912092e4df7bad1bdaa/python/cpython/issues/105690
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/162ef70a9efd51363d444fe60ccb44c20a5807ac76d2d912092e4df7bad1bdaa/python/cpython/issues/105690
og:image:altWhen importing PyQt6 with Python 3.12.0b2 (as well as on the current git 3.12, 0b305e8), it segfaults on exit. Program received signal SIGSEGV, Segmentation fault. 0x000055555572563a in _PyInterpre...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameThe-Compiler
hostnamegithub.com
expected-hostnamegithub.com
Nonec0d8175e41e0e55b9e984c935b24b808cabab919dd3174aa45dac3ef503ed1af
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
release99aab454e5ddc8df30805fb76c114c3008a15842
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/105690#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F105690
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%2F105690
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/105690
Reloadhttps://github.com/python/cpython/issues/105690
Reloadhttps://github.com/python/cpython/issues/105690
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/105690
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/105690
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/105690
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/105690
3.12: "Python memory allocator called without holding the GIL" with PyMem_Free as Py_AtExithttps://github.com/python/cpython/issues/105690#top
3.12only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.12%22
3.13bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.13%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/The-Compiler
https://github.com/The-Compiler
The-Compilerhttps://github.com/The-Compiler
on Jun 12, 2023https://github.com/python/cpython/issues/105690#issue-1752736136
0b305e8https://github.com/python/cpython/commit/0b305e8d36c5ac5dc83f0c09e7e2b3360b992eea
maintainer sayshttps://www.riverbankcomputing.com/pipermail/pyqt/2023-June/045332.html
https://docs.python.org/3/c-api/sys.html#c.Py_AtExithttps://docs.python.org/3/c-api/sys.html#c.Py_AtExit
6036c3ehttps://github.com/python/cpython/commit/6036c3e856f033bf13e929536e7bf127fdd921c9
#101161https://github.com/python/cpython/pull/101161
on their Mercurial serverhttps://www.riverbankcomputing.com/hg/sip/file/tip/sipbuild/module/source/13
@philthompson10https://github.com/philthompson10
@ericsnowcurrentlyhttps://github.com/ericsnowcurrently
3.12only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.12%22
3.13bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.13%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
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.