René's URL Explorer Experiment


Title: Creating an ungodly amount of sub interpreters in a short amount of time causes memory debug assertions. · Issue #123134 · python/cpython · GitHub

Open Graph Title: Creating an ungodly amount of sub interpreters in a short amount of time causes memory debug assertions. · Issue #123134 · python/cpython

X Title: Creating an ungodly amount of sub interpreters in a short amount of time causes memory debug assertions. · Issue #123134 · python/cpython

Description: Bug report Bug description: Hello. While working on a small joke program, I found a possible memory corruption issue (it could also be a threading issue?) when using the Python C API in a debug only build to quickly create, execute pytho...

Open Graph Description: Bug report Bug description: Hello. While working on a small joke program, I found a possible memory corruption issue (it could also be a threading issue?) when using the Python C API in a debug onl...

X Description: Bug report Bug description: Hello. While working on a small joke program, I found a possible memory corruption issue (it could also be a threading issue?) when using the Python C API in a debug onl...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Creating an ungodly amount of sub interpreters in a short amount of time causes memory debug assertions.","articleBody":"# Bug report\n\n### Bug description:\n\nHello. While working on a small joke program, I found a possible memory corruption issue (it could also be a threading issue?) when using the Python C API in a debug only build to quickly create, execute python code, and then destroy *463 sub interpreters*. Before I post the code sample and the debug output I'm using a somewhat unique build environment for a Windows developer.\n\n - clang++ 18.1.7 for x86_64-pc-windows-msvc\n - Visual Studio Build Tools 2022 17.11.0\n -  CMake 3.30\n - Python 3.12.5\n - ninja 1.12.1\n\nWhen running the code sample I've attached at the bottom of this post, I am unable to get the exact same output each time, though the traceback does fire in the same location (Due to the size of the traceback I've not attached it, as it's about 10 MB of text for each thread). Additionally, I sometimes have to run the executable several times to get the error to occur. Lastly, release builds do *not* exhibit any thread crashes or issues as the debug assertions never fire or execute.\n\nThe error output seems to also halt in some cases, either because of stack failure or some other issue I was unable to determine and seemed to possibly be outside the scope of the issue presented here. I have the entire error output from one execution where I was able to save the output.\n\n```\nDebug memory block at address p=00000267272D6030: API 'p'\n    16718206241729413120 bytes originally requested\n    The 7 pad bytes at p-7 are not all FORBIDDENBYTE (0xfd):\n        at p-7: 0xa0 *** OUCH\n        at p-6: 0x00 *** OUCH\n        at p-5: 0x00Hello, world! From Thread 31\nHello, world! From Thread 87\n *** OUCH\n        at p-4: 0xfd\nHello, world! From Thread 43\nHello, world! From Thread 279\nGenerating thread state 314\n        at p-3: 0xfd\n        at p-2: 0xfd\nHello, world! From Thread 168\nGenerating thread state 315\n        at p-1: 0xfd\n    Because memory is corrupted at the start, the count of bytes requested\n       may be bogus, and checking the trailing pad bytes may segfault.\nGenerating thread state 316\nGenerating thread state 317\n    The 8 pad bytes at tail=E8030267272D6030 are\n```\n\nThe output cut off after this, as the entire program crashed, taking my terminal with it 😅 \n\nYou'll find the MRE code below. I've also added a minimal version of CMakeLists.txt file I used so anyone can recreate the build with the code below (Any warnings, or additional settings I have do not affect whether the error occurs or not). The code appears to breaks inside of `_PyObject_DebugDumpAddress`, based on what debugging I was able to do with WinDbg. \n\n\u003e [!IMPORTANT]\n\u003e `std::jthread` calls `.join()` on destruction, so all threads auto-join once the `std::vector` goes out of scope.\n\u003e \n\u003e Additionally this code exhibits the same behavior regardless of whether it is a `thread_local` or declared within the lambda passed to `std::thread`\n\nmain.cxx\n```cpp\n#include \u003cvector\u003e\n#include \u003cthread\u003e\n#include \u003ccstdlib\u003e\n#include \u003cprint\u003e\n\n#include \u003cPython.h\u003e\n\nnamespace {\n\nstatic thread_local inline PyThreadState* state = nullptr;\nstatic inline constexpr auto MAX_STATES = 463; \nstatic inline constexpr auto config = PyInterpreterConfig {\n  .use_main_obmalloc = 0,\n  .allow_fork = 0,\n  .allow_exec = 0,\n  .allow_threads = 0,\n  .allow_daemon_threads = 0,\n  .check_multi_interp_extensions = 1,\n  .gil = PyInterpreterConfig_OWN_GIL,\n};\n\n} /* nameless namespace */\n\nvoid execute () {\n  std::vector\u003cstd::jthread\u003e tasks { };\n  tasks.reserve(MAX_STATES);\n  for (auto count = 0zu; count \u003c tasks.capacity(); count++) {\n    std::println(\"Generating thread state {}\", count);\n    tasks.emplace_back([count] {\n      if (auto status = Py_NewInterpreterFromConfig(\u0026state, \u0026config); PyStatus_IsError(status)) {\n        std::println(\"Failed to initialize thread state {}\", count);\n        return;\n      }\n      auto text = std::format(R\"(print(\"Hello, world! From Thread {}\"))\", count);\n      auto globals = PyDict_New();\n      auto code = Py_CompileString(text.data(), __FILE__, Py_eval_input);\n      auto result = PyEval_EvalCode(code, globals, globals);\n      Py_DecRef(result);\n      Py_DecRef(code);\n      Py_DecRef(globals);\n      Py_EndInterpreter(state);\n      state = nullptr;\n    });\n  }\n}\n\nint main() {\n  PyConfig config {};\n  PyConfig_InitIsolatedConfig(\u0026config);\n  if (auto status = Py_InitializeFromConfig(\u0026config); PyStatus_IsError(status)) {\n    std::println(\"Failed to initialize with isolated config: {}\", status.err_msg);\n    return EXIT_FAILURE;\n  }\n  PyConfig_Clear(\u0026config);\n  execute();\n  Py_Finalize();\n}\n```\nCMakeLists.txt\n```cmake\ncmake_minimum_required(VERSION 3.30)\nproject(463-interpreters LANGUAGES C CXX)\n\nfind_package(Python 3.12 REQUIRED COMPONENTS Development.Embed)\n\nset(CMAKE_MSVC_RUNTIME_LIBRARY \"MultiThreaded$\u003c$\u003cCONFIG:Debug\u003e:Debug\u003e\")\n\nadd_executable(${PROJECT_NAME})\ntarget_sources(${PROJECT_NAME} PRIVATE main.cxx)\ntarget_compile_features(${PROJECT_NAME} PRIVATE cxx_std_23)\ntarget_precompile_headers(${PROJECT_NAME} PRIVATE \u003cPython.h\u003e)\ntarget_link_libraries(${PROJECT_NAME} PRIVATE Python::Python)\n```\n\nCommand to build + run\n```shell\n$ cmake -Bbuild -S. -G \"Ninja\"\n$ cmake --build build \u0026\u0026 .\\build\\463-interpreters.exe\n```\n\n### CPython versions tested on:\n\n3.12\n\n### Operating systems tested on:\n\nWindows","author":{"url":"https://github.com/bruxisma","@type":"Person","name":"bruxisma"},"datePublished":"2024-08-19T05:11:50.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":88},"url":"https://github.com/123134/cpython/issues/123134"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:655b5136-1134-dea9-959f-7cb965dd4261
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8A72:9445B:2C78011:3C00DCE:696AEE93
html-safe-noncede1184f31b925fe4a8e9157a828042e7142666038c01ae9c486eae13715c3e47
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QTcyOjk0NDVCOjJDNzgwMTE6M0MwMERDRTo2OTZBRUU5MyIsInZpc2l0b3JfaWQiOiIyMTIwOTU1OTgxODMzMzY3MTg4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacce4cac8480eaa4691ace298d992d94d0c38a808923e460553b5f200e8be1bfeb
hovercard-subject-tagissue:2472472817
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/123134/issue_layout
twitter:imagehttps://opengraph.githubassets.com/5715f03f29f1030f5a745bd9d63f5813704016b7d6c94a0fb9a1bbc5ac7896ae/python/cpython/issues/123134
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/5715f03f29f1030f5a745bd9d63f5813704016b7d6c94a0fb9a1bbc5ac7896ae/python/cpython/issues/123134
og:image:altBug report Bug description: Hello. While working on a small joke program, I found a possible memory corruption issue (it could also be a threading issue?) when using the Python C API in a debug onl...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamebruxisma
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/123134#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F123134
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%2F123134
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/123134
Reloadhttps://github.com/python/cpython/issues/123134
Reloadhttps://github.com/python/cpython/issues/123134
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/123134
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/123134
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/123134
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/123134
Creating an ungodly amount of sub interpreters in a short amount of time causes memory debug assertions.https://github.com/python/cpython/issues/123134#top
topic-C-APIhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-C-API%22
topic-subinterpretershttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-subinterpreters%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/bruxisma
https://github.com/bruxisma
bruxismahttps://github.com/bruxisma
on Aug 19, 2024https://github.com/python/cpython/issues/123134#issue-2472472817
topic-C-APIhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-C-API%22
topic-subinterpretershttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-subinterpreters%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%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.