Title: Crash in `_io_TextIOWrapper_write_impl` when running `tracemalloc.clear_traces` in threads · Issue #144763 · python/cpython · GitHub
Open Graph Title: Crash in `_io_TextIOWrapper_write_impl` when running `tracemalloc.clear_traces` in threads · Issue #144763 · python/cpython
X Title: Crash in `_io_TextIOWrapper_write_impl` when running `tracemalloc.clear_traces` in threads · Issue #144763 · python/cpython
Description: Crash report What happened? Running the code below will non-deterministically cause a segfault or abort in _io_TextIOWrapper_write_impl in the !PyList_CheckExact(self->pending_bytes) assertion. from sys import stdout from threading impor...
Open Graph Description: Crash report What happened? Running the code below will non-deterministically cause a segfault or abort in _io_TextIOWrapper_write_impl in the !PyList_CheckExact(self->pending_bytes) assertion. fro...
X Description: Crash report What happened? Running the code below will non-deterministically cause a segfault or abort in _io_TextIOWrapper_write_impl in the !PyList_CheckExact(self->pending_bytes) assertion. ...
Opengraph URL: https://github.com/python/cpython/issues/144763
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Crash in `_io_TextIOWrapper_write_impl` when running `tracemalloc.clear_traces` in threads","articleBody":"# Crash report\n\n### What happened?\n\nRunning the code below will non-deterministically cause a segfault or abort in `_io_TextIOWrapper_write_impl` in the `!PyList_CheckExact(self->pending_bytes)` assertion.\n\n```python\nfrom sys import stdout\nfrom threading import Thread\nfrom time import sleep\nfrom tracemalloc import clear_traces, start, get_traceback_limit\n\ndef print_to_file(text):\n get_traceback_limit()\n stdout.write(\"\")\n clear_traces()\n sleep(0.04)\n clear_traces()\n\nalive = []\n\nstart()\nfor i in range(300):\n alive.append(Thread(target=print_to_file, args=(\"a\" * 800,)))\n\nfor t in alive:\n t.start()\n print(object)\n```\n\n\u003cdetails>\u003csummary>Segfault backtrace\u003c/summary>\n\u003cp>\n\n```\nThread 143 \"Thread-142 (pri\" received signal SIGSEGV, Segmentation fault.\n[Switching to Thread 0x7bfec37d66c0 (LWP 1476230)]\n0x000055555622f434 in _Py_TYPE_impl (ob=0x0) at ./Include/object.h:313\n313 return ob->ob_type;\n\n#0 0x000055555622f434 in _Py_TYPE_impl (ob=0x0) at ./Include/object.h:313\n#1 _Py_IS_TYPE_impl (ob=0x0, type=\u003coptimized out>) at ./Include/object.h:328\n#2 _io_TextIOWrapper_write_impl (self=0x7bffb4361110, text=\u003coptimized out>) at ./Modules/_io/textio.c:1765\n#3 _io_TextIOWrapper_write (self=0x7bffb4361110, arg=0x5555569275c8 \u003c_PyRuntime+96968>) at ./Modules/_io/clinic/textio.c.h:803\n#4 0x0000555555ecb860 in _PyEval_EvalFrameDefault (tstate=\u003coptimized out>, frame=\u003coptimized out>, throwflag=\u003coptimized out>) at Python/generated_cases.c.h:2499\n#5 0x0000555555e96854 in _PyEval_EvalFrame (tstate=0x7e8ff7576210, frame=0x7e8ff7404328, throwflag=0) at ./Include/internal/pycore_ceval.h:118\n#6 _PyEval_Vector (tstate=0x7e8ff7576210, func=0x7bffb449b7d0, locals=0x0, args=0x7bff33fcf520, argcount=1, kwnames=0x0) at Python/ceval.c:2125\n#7 0x0000555555ac3110 in _PyObject_VectorcallTstate (tstate=tstate@entry=0x7e8ff7576210, callable=callable@entry=0x7bffb449b7d0, args=0x7bff33fcf520, nargsf=nargsf@entry=1,\n kwnames=kwnames@entry=0x0) at ./Include/internal/pycore_call.h:136\n#8 0x0000555555ac080a in method_vectorcall (method=0x7bff440d0070, args=\u003coptimized out>, nargsf=\u003coptimized out>, kwnames=\u003coptimized out>) at Objects/classobject.c:74\n#9 0x0000555555f582b3 in _PyObject_VectorcallTstate (tstate=0x7e8ff7576210, callable=0x7bff440d0070, args=0x7bff440e00e7, nargsf=17042036080667, kwnames=0x0)\n at ./Include/internal/pycore_call.h:136\n#10 context_run (self=0x7bffb4d82770, args=0x7bfec37d47b0, nargs=1, kwnames=0x0) at Python/context.c:727\n#11 0x0000555555e997da in _PyCallMethodDescriptorFastWithKeywords_StackRefSteal (callable=callable@entry=..., meth=0x555556740560 \u003cPyContext_methods+160>, self=self@entry=0x7bffb4d82770,\n arguments=0x7e8ff74042f8, total_args=total_args@entry=2) at Python/ceval.c:913\n#12 0x0000555555ec9cad in _PyEval_EvalFrameDefault (tstate=\u003coptimized out>, frame=\u003coptimized out>, throwflag=\u003coptimized out>) at Python/generated_cases.c.h:3852\n#13 0x0000555555e96854 in _PyEval_EvalFrame (tstate=0x7e8ff7576210, frame=0x7e8ff7404220, throwflag=0) at ./Include/internal/pycore_ceval.h:118\n#14 _PyEval_Vector (tstate=0x7e8ff7576210, func=0x7bffb449b8b0, locals=0x0, args=0x7bff33fcd120, argcount=1, kwnames=0x0) at Python/ceval.c:2125\n#15 0x0000555555ac3110 in _PyObject_VectorcallTstate (tstate=tstate@entry=0x7e8ff7576210, callable=callable@entry=0x7bffb449b8b0, args=0x7bff33fcd120, nargsf=nargsf@entry=1,\n kwnames=kwnames@entry=0x0) at ./Include/internal/pycore_call.h:136\n#16 0x0000555555ac080a in method_vectorcall (method=0x7bffb457ff70, args=\u003coptimized out>, nargsf=\u003coptimized out>, kwnames=\u003coptimized out>) at Objects/classobject.c:74\n#17 0x0000555555ab955f in _PyVectorcall_Call (tstate=\u003coptimized out>, func=\u003coptimized out>, callable=\u003coptimized out>, tuple=0x55555693a1f8 \u003c_PyRuntime+173816>, kwargs=\u003coptimized out>)\n at Objects/call.c:273\n#18 0x00005555562b0b59 in thread_run (boot_raw=boot_raw@entry=0x7c6ff6fe83e0) at ./Modules/_threadmodule.c:387\n#19 0x00005555560f8a26 in pythread_wrapper (arg=0x7c3ff70fa0a0) at Python/thread_pthread.h:234\n#20 0x000055555589b34b in asan_thread_start(void*) ()\n#21 0x00007ffff7ca3d64 in start_thread (arg=\u003coptimized out>) at ./nptl/pthread_create.c:448\n#22 0x00007ffff7d373fc in __GI___clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78\n```\n\n\u003c/p>\n\u003c/details>\n\n\n\u003cdetails>\u003csummary>Abort backtrace\u003c/summary>\n\u003cp>\n\n```\npython: ./Modules/_io/textio.c:1765: PyObject *_io_TextIOWrapper_write_impl(textio *, PyObject *): Assertion `!PyList_CheckExact(self->pending_bytes)' failed.\n\nThread 65 \"Thread-64 (prin\" received signal SIGABRT, Aborted.\n[Switching to Thread 0x7bff14a596c0 (LWP 1478715)]\n\n#0 __pthread_kill_implementation (threadid=\u003coptimized out>, signo=6, no_tid=0) at ./nptl/pthread_kill.c:44\n#1 __pthread_kill_internal (threadid=\u003coptimized out>, signo=6) at ./nptl/pthread_kill.c:89\n#2 __GI___pthread_kill (threadid=\u003coptimized out>, signo=signo@entry=6) at ./nptl/pthread_kill.c:100\n#3 0x00007ffff7c45e2e in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26\n#4 0x00007ffff7c28888 in __GI_abort () at ./stdlib/abort.c:77\n#5 0x00007ffff7c287f0 in __assert_fail_base (fmt=\u003coptimized out>, assertion=\u003coptimized out>, file=\u003coptimized out>, line=\u003coptimized out>, function=\u003coptimized out>) at ./assert/assert.c:118\n#6 0x00007ffff7c3c19f in __assert_fail (assertion=\u003coptimized out>, file=\u003coptimized out>, line=\u003coptimized out>, function=\u003coptimized out>) at ./assert/assert.c:127\n#7 0x000055555622f965 in _io_TextIOWrapper_write_impl (self=0x7bffb4361110, text=\u003coptimized out>) at ./Modules/_io/textio.c:1765\n#8 _io_TextIOWrapper_write (self=0x7bffb4361110, arg=0x5555569275c8 \u003c_PyRuntime+96968>) at ./Modules/_io/clinic/textio.c.h:803\n#9 0x0000555555ecb860 in _PyEval_EvalFrameDefault (tstate=\u003coptimized out>, frame=\u003coptimized out>, throwflag=\u003coptimized out>) at Python/generated_cases.c.h:2499\n#10 0x0000555555e96854 in _PyEval_EvalFrame (tstate=0x7e8ff741d210, frame=0x7e8ff718e328, throwflag=0) at ./Include/internal/pycore_ceval.h:118\n#11 _PyEval_Vector (tstate=0x7e8ff741d210, func=0x7bffb449b7d0, locals=0x0, args=0x7bff98169a20, argcount=1, kwnames=0x0) at Python/ceval.c:2125\n#12 0x0000555555ac3110 in _PyObject_VectorcallTstate (tstate=tstate@entry=0x7e8ff741d210, callable=callable@entry=0x7bffb449b7d0, args=0x7bff98169a20, nargsf=nargsf@entry=1,\n kwnames=kwnames@entry=0x0) at ./Include/internal/pycore_call.h:136\n#13 0x0000555555ac080a in method_vectorcall (method=0x7bffda0d0070, args=\u003coptimized out>, nargsf=\u003coptimized out>, kwnames=\u003coptimized out>) at Objects/classobject.c:74\n#14 0x0000555555f582b3 in _PyObject_VectorcallTstate (tstate=0x7e8ff741d210, callable=0x7bffda0d0070, args=0x7bff14a596c0, nargsf=22, kwnames=0x0) at ./Include/internal/pycore_call.h:136\n#15 context_run (self=0x7bffb4d80850, args=0x7bff14a577b0, nargs=1, kwnames=0x0) at Python/context.c:727\n#16 0x0000555555e997da in _PyCallMethodDescriptorFastWithKeywords_StackRefSteal (callable=callable@entry=..., meth=0x555556740560 \u003cPyContext_methods+160>, self=self@entry=0x7bffb4d80850,\n arguments=0x7e8ff718e2f8, total_args=total_args@entry=2) at Python/ceval.c:913\n#17 0x0000555555ec9cad in _PyEval_EvalFrameDefault (tstate=\u003coptimized out>, frame=\u003coptimized out>, throwflag=\u003coptimized out>) at Python/generated_cases.c.h:3852\n#18 0x0000555555e96854 in _PyEval_EvalFrame (tstate=0x7e8ff741d210, frame=0x7e8ff718e220, throwflag=0) at ./Include/internal/pycore_ceval.h:118\n#19 _PyEval_Vector (tstate=0x7e8ff741d210, func=0x7bffb449b8b0, locals=0x0, args=0x7bff98168120, argcount=1, kwnames=0x0) at Python/ceval.c:2125\n#20 0x0000555555ac3110 in _PyObject_VectorcallTstate (tstate=tstate@entry=0x7e8ff741d210, callable=callable@entry=0x7bffb449b8b0, args=0x7bff98168120, nargsf=nargsf@entry=1,\n kwnames=kwnames@entry=0x0) at ./Include/internal/pycore_call.h:136\n#21 0x0000555555ac080a in method_vectorcall (method=0x7bffb44e2a10, args=\u003coptimized out>, nargsf=\u003coptimized out>, kwnames=\u003coptimized out>) at Objects/classobject.c:74\n#22 0x0000555555ab955f in _PyVectorcall_Call (tstate=\u003coptimized out>, func=\u003coptimized out>, callable=\u003coptimized out>, tuple=0x55555693a1f8 \u003c_PyRuntime+173816>, kwargs=\u003coptimized out>)\n at Objects/call.c:273\n#23 0x00005555562b0b59 in thread_run (boot_raw=boot_raw@entry=0x7c6ff6fe61c0) at ./Modules/_threadmodule.c:387\n#24 0x00005555560f8a26 in pythread_wrapper (arg=0x7c3ff70db460) at Python/thread_pthread.h:234\n#25 0x000055555589b34b in asan_thread_start(void*) ()\n#26 0x00007ffff7ca3d64 in start_thread (arg=\u003coptimized out>) at ./nptl/pthread_create.c:448\n#27 0x00007ffff7d373fc in __GI___clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78)\n```\n\n\u003c/p>\n\u003c/details>\n\nAffected code:\nhttps://github.com/python/cpython/blob/66da7bf6fe7b81e3ecc9c0a25bd47d4616c8d1a6/Modules/_io/textio.c#L1757-L1769\n\n\n\nFound using [fusil](https://github.com/devdanzin/fusil) by @vstinner.\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n### Output from running 'python -VV' on the command line:\n\nPython 3.15.0a6+ free-threading build (heads/main:b488f338cf0, Feb 12 2026, 17:28:06) [Clang 21.1.2 (2ubuntu6)]\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-144779\n* gh-144965\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/devdanzin","@type":"Person","name":"devdanzin"},"datePublished":"2026-02-12T21:04:13Z","url":"https://github.com/python/cpython/issues/144763"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:7c3c6161-6f13-14ce-2ca4-0606eb7bb663 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9264:28A483:1662B03:1DA30C5:6B020255 |
| html-safe-nonce | ec86af6d63ecf79d2edd75ccc6d1587a45b6968cf84303780271241a043e16d0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MjY0OjI4QTQ4MzoxNjYyQjAzOjFEQTMwQzU6NkIwMjAyNTUiLCJ2aXNpdG9yX2lkIjoiODI2MDUxNzU3MjkyNDAxNTE4OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c17d921d627aff715bb2fab991627cef44f10ec6c3448e2bfa22dcc28e25834d |
| hovercard-subject-tag | issue:3934022799 |
| 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/144763/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6d23c662f6fb0e07a921976ae2ebe0daa3c2784536100ba7b9fb318a77c28edb/python/cpython/issues/144763 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6d23c662f6fb0e07a921976ae2ebe0daa3c2784536100ba7b9fb318a77c28edb/python/cpython/issues/144763 |
| og:image:alt | Crash report What happened? Running the code below will non-deterministically cause a segfault or abort in _io_TextIOWrapper_write_impl in the !PyList_CheckExact(self->pending_bytes) assertion. fro... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | devdanzin |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width