Title: The REPL hangs under low memory on main · Issue #140080 · python/cpython · GitHub
Open Graph Title: The REPL hangs under low memory on main · Issue #140080 · python/cpython
X Title: The REPL hangs under low memory on main · Issue #140080 · python/cpython
Description: Bug report Bug description: Its kind of the same issue like #134163 so cc @ZeroIntensity @picnixz but the root cause is very different import _testcapi _testcapi.set_nomemory(100) # or 0 or 1000 it will print the error and hang forever [...
Open Graph Description: Bug report Bug description: Its kind of the same issue like #134163 so cc @ZeroIntensity @picnixz but the root cause is very different import _testcapi _testcapi.set_nomemory(100) # or 0 or 1000 it...
X Description: Bug report Bug description: Its kind of the same issue like #134163 so cc @ZeroIntensity @picnixz but the root cause is very different import _testcapi _testcapi.set_nomemory(100) # or 0 or 1000 it...
Opengraph URL: https://github.com/python/cpython/issues/140080
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"The REPL hangs under low memory on main","articleBody":"# Bug report\n\n### Bug description:\n\nIts kind of the same issue like https://github.com/python/cpython/issues/134163\nso cc @ZeroIntensity @picnixz \n\nbut the root cause is very different \n\n\n```python\nimport _testcapi\n_testcapi.set_nomemory(100) # or 0 or 1000\n```\nit will print the error and hang forever\n\n```py\n[hyi@rocky cpython]$ ./python \nPython 3.15.0a0 (heads/main:8e0bf4fe5d7, Oct 14 2025, 14:01:02) [GCC 11.5.0 20240719 (Red Hat 11.5.0-5)] on linux\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n\u003e\u003e\u003e import _testcapi\n\u003e\u003e\u003e _testcapi.set_nomemory(0)\nobject address : 0xffff9c12dea0\nobject refcount : 3\nobject type : 0x927c48\nobject type name: MemoryError\nobject repr : \nlost sys.stderr\n# hang here\n```\n\nthe root cause is easy but the fix maybe hard and need to discuss so only issue\nand digging here no patch\n\nsome dig:\n\n- it only happens in main 3.15 and recent commits\n- it happends on all system\n- both old and default REPL hava it\n- its hard to reproduce without repl\n\nthe root cause can check bt\n\n```bt\n➜ ~ lldb -p 23325\n(lldb) process attach --pid 23325\nwarning: python.exe was compiled with optimization - stepping may behave oddly; variables may not be available.\nProcess 23325 stopped\n* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP\n frame #0: 0x0000000100bac6c4 python.exe`BaseException_clear(op=0x00000001011c1e40) at exceptions.c:135:5 [opt]\n 132 \tBaseException_clear(PyObject *op)\n 133 \t{\n 134 \t PyBaseExceptionObject *self = PyBaseExceptionObject_CAST(op);\n-\u003e 135 \t Py_CLEAR(self-\u003edict);\n 136 \t Py_CLEAR(self-\u003eargs);\n 137 \t Py_CLEAR(self-\u003enotes);\n 138 \t Py_CLEAR(self-\u003etraceback);\nTarget 0: (python.exe) stopped.\nExecutable binary set to \"/Users/hyi/prs/cpython/python.exe\".\nArchitecture set to: arm64-apple-macosx-.\n(lldb) bt\n* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP\n * frame #0: 0x0000000100bac6c4 python.exe`BaseException_clear(op=0x00000001011c1e40) at exceptions.c:135:5 [opt]\n frame #1: 0x0000000100bac58c python.exe`MemoryError_dealloc(op=0x00000001011c1e40) at exceptions.c:4099:11 [opt]\n frame #2: 0x0000000100bf8fac python.exe`_Py_Dealloc(op=0x00000001011c1e40) at object.c:3200:5 [opt]\n frame #3: 0x0000000100d0c9ac python.exe`format_unraisable_v [inlined] Py_DECREF(op=0x00000001011c1e40) at refcount.h:418:9 [opt]\n frame #4: 0x0000000100d0c9a4 python.exe`format_unraisable_v [inlined] Py_XDECREF(op=0x00000001011c1e40) at refcount.h:511:9 [opt]\n frame #5: 0x0000000100d0c9a4 python.exe`format_unraisable_v(format=\u003cunavailable\u003e, va=\"8X\\xa2\\U00000001\\U00000001\", obj=0x0000000000000000) at errors.c:1746:5 [opt]\n frame #6: 0x0000000100d0c428 python.exe`PyErr_FormatUnraisable(format=\u003cunavailable\u003e) at errors.c:1769:5 [opt]\n frame #7: 0x0000000100d8017c python.exe`atexit_callfuncs(state=\u003cunavailable\u003e) at atexitmodule.c:113:9 [opt] [artificial]\n frame #8: 0x0000000100d80070 python.exe`_PyAtExit_Call(interp=\u003cunavailable\u003e) at atexitmodule.c:151:5 [opt] [artificial]\n frame #9: 0x0000000100d471b0 python.exe`make_pre_finalization_calls(tstate=0x0000000100ff8bc0, subinterpreters=1) at pylifecycle.c:2108:9 [opt]\n frame #10: 0x0000000100d468dc python.exe`_Py_Finalize(runtime=\u003cunavailable\u003e) at pylifecycle.c:2167:5 [opt]\n frame #11: 0x0000000100d46828 python.exe`Py_FinalizeEx at pylifecycle.c:2378:12 [opt] [artificial]\n frame #12: 0x0000000100d76854 python.exe`Py_RunMain at main.c:774:9 [opt]\n frame #13: 0x0000000100d76fec python.exe`pymain_main(args=0x000000016f2b6140) at main.c:802:12 [opt]\n frame #14: 0x0000000100d7708c python.exe`Py_BytesMain(argc=\u003cunavailable\u003e, argv=\u003cunavailable\u003e) at main.c:826:12 [opt]\n frame #15: 0x000000019a2e5d54 dyld`start + 7184\n(lldb) \n```\n\n- with the perf can check the fucntion\n```bt\n[hyi@rocky ~]$ perf annotate -l --stdio --symbol PyErr_FormatUnraisable\n\nSorted summary for file /home/hyi/cpython/python\n----------------------------------------------\n\n 55.56 errors.c:1765\n 29.63 errors.c:1771\n 14.81 errors.c:1768\n Percent | Source code \u0026 Disassembly of python for task-clock:upppH (27 samples, percent: local period)\n------------------------------------------------------------------------------------------------------------\n :\n :\n :\n : 3 Disassembly of section .text:\n :\n : 5 0000000000614ac0 \u003cPyErr_FormatUnraisable\u003e:\n : 6 _PyErr_Clear(tstate); /* Just in case */\n : 7 }\n :\n : 9 void\n : 10 PyErr_FormatUnraisable(const char *format, ...)\n : 11 {\n 0.00 : 614ac0: stp x29, x30, [sp, #-272]!\n : 13 va_list va;\n :\n : 15 va_start(va, format);\n 0.00 : 614ac4: mov w9, #0xffffffc8 // #-56\n 0.00 : 614ac8: mov w8, #0xffffff80 // #-128\n : 18 {\n 0.00 : 614acc: mov x29, sp\n : 20 va_start(va, format);\n 0.00 : 614ad0: add x10, sp, #0xd0\n 0.00 : 614ad4: add x11, sp, #0x110\n```\n\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nmacOS\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-140103\n* gh-140161\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/yihong0618","@type":"Person","name":"yihong0618"},"datePublished":"2025-10-14T07:25:05.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/140080/cpython/issues/140080"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b4e7bc9e-f763-5b76-5550-785908ffea3d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ACF6:FE603:6B8310:8B6CE6:696AEC41 |
| html-safe-nonce | cd4ec0e3675eb8ef510f3468cfbfb5c42ab680aace3f2a341a21da7b5535a55e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQ0Y2OkZFNjAzOjZCODMxMDo4QjZDRTY6Njk2QUVDNDEiLCJ2aXNpdG9yX2lkIjoiNTI4MjY4Mjg4NTMzNDgyMTk1MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 83a8bcbfbf19c04c437b81e22b72dd31661822edf7ea8abd0e48ea2bf27bef4e |
| hovercard-subject-tag | issue:3512703749 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/140080/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ba5e75c8f94148f59852474c401001bb11bc774ca2ee1b832adc1591c0182d1f/python/cpython/issues/140080 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ba5e75c8f94148f59852474c401001bb11bc774ca2ee1b832adc1591c0182d1f/python/cpython/issues/140080 |
| og:image:alt | Bug report Bug description: Its kind of the same issue like #134163 so cc @ZeroIntensity @picnixz but the root cause is very different import _testcapi _testcapi.set_nomemory(100) # or 0 or 1000 it... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | yihong0618 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width