Title: Py_Initialize() in a background thread crashes on free-threaded release builds of 3.14 after the mimalloc 2.5.2 update · Issue #160588 · python/cpython · GitHub
Open Graph Title: Py_Initialize() in a background thread crashes on free-threaded release builds of 3.14 after the mimalloc 2.5.2 update · Issue #160588 · python/cpython
X Title: Py_Initialize() in a background thread crashes on free-threaded release builds of 3.14 after the mimalloc 2.5.2 update · Issue #160588 · python/cpython
Description: Crash report On the 3.14 branch, a free-threaded release build (./configure --disable-gil) crashes when Py_Initialize() is called in a thread other than the main thread. test_embed's test_init_in_background_thread, added for gh-123022, f...
Open Graph Description: Crash report On the 3.14 branch, a free-threaded release build (./configure --disable-gil) crashes when Py_Initialize() is called in a thread other than the main thread. test_embed's test_init_in_b...
X Description: Crash report On the 3.14 branch, a free-threaded release build (./configure --disable-gil) crashes when Py_Initialize() is called in a thread other than the main thread. test_embed's test_init_...
Opengraph URL: https://github.com/python/cpython/issues/160588
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Py_Initialize() in a background thread crashes on free-threaded release builds of 3.14 after the mimalloc 2.5.2 update","articleBody":"### Crash report\n\nOn the 3.14 branch, a free-threaded release build (`./configure --disable-gil`) crashes when `Py_Initialize()` is called in a thread other than the main thread. `test_embed`'s `test_init_in_background_thread`, added for gh-123022, fails on every run: `./Programs/_testembed test_init_in_background_thread` crashed 20 times out of 20. Under lldb (trimmed):\n\n```\n$ lldb -- ./Programs/_testembed test_init_in_background_thread\n* thread #2, stop reason = EXC_BAD_ACCESS (code=2, address=0x100411738)\n frame #0: chacha_block(ctx=0x00000001004116f8) at random.c:67:20\n frame #1: chacha_next32 at random.c:83:5 [inlined]\n frame #2: _mi_random_next at random.c:154:22 [inlined]\n frame #3: _mi_heap_random_next(heap=0x00000001004116c0) at heap.c:281:10 [inlined]\n frame #4: _mi_os_get_aligned_hint(try_alignment=33554432, size=1107296256) at os.c:129:19\n frame #5: unix_mmap_prim_aligned at prim.c:281:18\n ...\n frame #11: mi_reserve_os_memory_ex(size=1073741824, ...) at arena.c:917:17\n```\n\nIt also fails in the tail-call workflow on my fork (x86_64-unknown-linux-gnu/gcc-free-threading, `bad returncode -11`): https://github.com/devdavidejesus/cpython/actions/runs/40045549694\n\nIn 3.14.9, `_mi_os_get_aligned_hint()` and `mi_os_claim_huge_pages()` in `Objects/mimalloc/os.c` only call `_mi_heap_random_next()` if `mi_heap_is_initialized(heap)`; that check is the gh-123022 fix. The mimalloc 2.5.2 update (gh-159111, 1bcc0d165ae on 3.14) dropped it. In a new thread the default heap is still `_mi_heap_empty`, which is `const`, so the write in `chacha_block()` faults (`heap` in frame #3 is `_mi_heap_empty`).\n\nDebug builds are not affected, because this code is under `#if (MI_SECURE>0 || MI_DEBUG==0)` and `MI_DEBUG` is 2 with `Py_DEBUG`. The free-threaded jobs in the main CI workflow are debug builds, which is probably why this was not caught there.\n\nThe check is also missing on main and 3.15, but this test does not crash on main: there, as on 3.15, free-threaded builds use mimalloc for the raw domain (`MIMALLOC_RAWALLOC`), so the first `PyMem_RawMalloc()` call in the thread initializes its default heap. On 3.14 the raw domain uses `malloc()`.\n\nRestoring the check fixes the crash: the test then passes 20 of 20 times, and `test_embed` passes. (For main, gh-113141 notes that with mimalloc v3, proposed in gh-159718, \"The gh-123022 patch no longer applies\".)\n\n### CPython versions tested on:\n\n3.14, CPython main branch\n\n### Operating systems tested on:\n\nmacOS, Linux\n\n### Output from running 'python -VV' on the command line:\n\nPython 3.14.9+ free-threading build (remotes/upstream/3.14:aa3903e80a4, Oct 24 2026, 08:12:26) [Clang 21.0.0 (clang-2100.3.34.2)]\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-160589\n* gh-160611\n* gh-160612\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/devdavidejesus","@type":"Person","name":"devdavidejesus"},"datePublished":"2026-10-24T11:37:37Z","url":"https://github.com/python/cpython/issues/160588"}
| 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:5d0183bf-3733-b2ca-00d5-fa67818d89c7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A8F2:33444D:3633E7E:480B600:6B0209D0 |
| html-safe-nonce | b0fedbcb9de8c854c7b67bffa8e0583594a4f829a1cc04045ed4f49c9dce7745 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOEYyOjMzNDQ0RDozNjMzRTdFOjQ4MEI2MDA6NkIwMjA5RDAiLCJ2aXNpdG9yX2lkIjoiMjk4NzcxNDE0NDkzMDc2MTE2OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3efb18989ccb11f983ee338f0537de4c257e06beb96baeb84c025594256f392f |
| hovercard-subject-tag | issue:6012515221 |
| 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/160588/issue_layout |
| twitter:image | https://opengraph.githubassets.com/448464f0a4efbe97264680bcdfbffb0aab965310c4e6dbca756bfabfabd56659/python/cpython/issues/160588 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/448464f0a4efbe97264680bcdfbffb0aab965310c4e6dbca756bfabfabd56659/python/cpython/issues/160588 |
| og:image:alt | Crash report On the 3.14 branch, a free-threaded release build (./configure --disable-gil) crashes when Py_Initialize() is called in a thread other than the main thread. test_embed's test_init_in_b... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | devdavidejesus |
| 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 | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width