Title: [Bug]: 3.10 debug build crashes on interpreter exit · Issue #32509 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: 3.10 debug build crashes on interpreter exit · Issue #32509 · matplotlib/matplotlib
X Title: [Bug]: 3.10 debug build crashes on interpreter exit · Issue #32509 · matplotlib/matplotlib
Description: Bug summary I'm building a full debug Python environment (Python 3.12.4, numpy 2.4.6, pybind 3.1, contourpy 1.3.3, MPL 3.10.9) It seems that when MPL has been imported, the python interpreter shutdown will show a GIL error: Fatal Python ...
Open Graph Description: Bug summary I'm building a full debug Python environment (Python 3.12.4, numpy 2.4.6, pybind 3.1, contourpy 1.3.3, MPL 3.10.9) It seems that when MPL has been imported, the python interpreter shutd...
X Description: Bug summary I'm building a full debug Python environment (Python 3.12.4, numpy 2.4.6, pybind 3.1, contourpy 1.3.3, MPL 3.10.9) It seems that when MPL has been imported, the python interpreter s...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/32509
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: 3.10 debug build crashes on interpreter exit","articleBody":"### Bug summary\n\nI'm building a full debug Python environment (Python 3.12.4, numpy 2.4.6, pybind 3.1, contourpy 1.3.3, MPL 3.10.9)\n\nIt seems that when MPL has been imported, the python interpreter shutdown will show a GIL error:\n```\nFatal Python error: _PyInterpreterState_GET: the function must be called with the GIL held, after Python initialization and before Python finalization, but the GIL is released (the current Python thread state is NULL)\nPython runtime state: finalizing (tstate=0x00007ffbe152fca0)\n```\nIn release builds, this does not occur, but I suppose it's because there are less asserts on GIL state at shutdown.\n\nWhen debugging, the stack is\n```\n \tKernelBase.dll!00007ff843eb3122()\tUnknown\n \tpython312_d.dll!fatal_error_exit(int status) Line 2778\tC\n \tpython312_d.dll!fatal_error(int fd, int header, const char * prefix, const char * msg, int status) Line 2959\tC\n \tpython312_d.dll!_Py_FatalErrorFunc(const char * func, const char * msg) Line 2975\tC\n \tpython312_d.dll!_PyInterpreterState_GET() Line 131\tC\n \tpython312_d.dll!_Py_DECREF_DecRefTotal() Line 240\tC\n \tft2font_d.cp312-win_amd64.pyd!Py_DECREF(const char * filename, int lineno, _object * op) Line 688\tC++\n \tft2font_d.cp312-win_amd64.pyd!Py_XDECREF(_object * op) Line 798\tC++\n \tft2font_d.cp312-win_amd64.pyd!pybind11::handle::dec_ref() Line 300\tC++\n \tft2font_d.cp312-win_amd64.pyd!pybind11::object::~object() Line 395\tC++\n \tft2font_d.cp312-win_amd64.pyd!std::pair\u003cstd::string const ,pybind11::object>::~pair\u003cstd::string const ,pybind11::object>()\tC++\n \tft2font_d.cp312-win_amd64.pyd!std::pair\u003cstd::string const ,pybind11::object>::`scalar deleting destructor'(unsigned int)\tC++\n \tft2font_d.cp312-win_amd64.pyd!std::_Default_allocator_traits\u003cstd::allocator\u003cstd::_List_node\u003cstd::pair\u003cstd::string const ,pybind11::object>,void *>>>::destroy\u003cstd::pair\u003cstd::string const ,pybind11::object>>(std::allocator\u003cstd::_List_node\u003cstd::pair\u003cstd::string const ,pybind11::object>,void *>> & __formal, std::pair\u003cstd::string const ,pybind11::object> * const _Ptr) Line 741\tC++\n \tft2font_d.cp312-win_amd64.pyd!std::_List_node\u003cstd::pair\u003cstd::string const ,pybind11::object>,void *>::_Freenode\u003cstd::allocator\u003cstd::_List_node\u003cstd::pair\u003cstd::string const ,pybind11::object>,void *>>>(std::allocator\u003cstd::_List_node\u003cstd::pair\u003cstd::string const ,pybind11::object>,void *>> & _Al, std::_List_node\u003cstd::pair\u003cstd::string const ,pybind11::object>,void *> * _Ptr) Line 318\tC++\n \tft2font_d.cp312-win_amd64.pyd!std::_List_node\u003cstd::pair\u003cstd::string const ,pybind11::object>,void *>::_Free_non_head\u003cstd::allocator\u003cstd::_List_node\u003cstd::pair\u003cstd::string const ,pybind11::object>,void *>>>(std::allocator\u003cstd::_List_node\u003cstd::pair\u003cstd::string const ,pybind11::object>,void *>> & _Al, std::_List_node\u003cstd::pair\u003cstd::string const ,pybind11::object>,void *> * _Head) Line 329\tC++\n \tft2font_d.cp312-win_amd64.pyd!std::list\u003cstd::pair\u003cstd::string const ,pybind11::object>,std::allocator\u003cstd::pair\u003cstd::string const ,pybind11::object>>>::_Tidy() Line 1519\tC++\n \tft2font_d.cp312-win_amd64.pyd!std::list\u003cstd::pair\u003cstd::string const ,pybind11::object>,std::allocator\u003cstd::pair\u003cstd::string const ,pybind11::object>>>::~list\u003cstd::pair\u003cstd::string const ,pybind11::object>,std::allocator\u003cstd::pair\u003cstd::string const ,pybind11::object>>>() Line 1063\tC++\n \tft2font_d.cp312-win_amd64.pyd!std::_Hash\u003cstd::_Umap_traits\u003cstd::string,pybind11::object,std::_Uhash_compare\u003cstd::string,std::hash\u003cstd::string>,std::equal_to\u003cstd::string>>,std::allocator\u003cstd::pair\u003cstd::string const ,pybind11::object>>,0>>::~_Hash\u003cstd::_Umap_traits\u003cstd::string,pybind11::object,std::_Uhash_compare\u003cstd::string,std::hash\u003cstd::string>,std::equal_to\u003cstd::string>>,std::allocator\u003cstd::pair\u003cstd::string const ,pybind11::object>>,0>>()\tC++\n \tft2font_d.cp312-win_amd64.pyd!std::unordered_map\u003cstd::string,pybind11::object,std::hash\u003cstd::string>,std::equal_to\u003cstd::string>,std::allocator\u003cstd::pair\u003cstd::string const ,pybind11::object>>>::~unordered_map\u003cstd::string,pybind11::object,std::hash\u003cstd::string>,std::equal_to\u003cstd::string>,std::allocator\u003cstd::pair\u003cstd::string const ,pybind11::object>>>()\tC++\n \tft2font_d.cp312-win_amd64.pyd!p11x::`anonymous namespace'::`dynamic atexit destructor for 'enums''()\tC++\n \tucrtbased.dll!00007fff08e62b99()\tUnknown\n \tucrtbased.dll!00007fff08e625c5()\tUnknown\n \tucrtbased.dll!00007fff08e62717()\tUnknown\n \tucrtbased.dll!00007fff08e62d44()\tUnknown\n \tft2font_d.cp312-win_amd64.pyd!__scrt_dllmain_uninitialize_c() Line 398\tC++\n>\tft2font_d.cp312-win_amd64.pyd!dllmain_crt_process_detach(const bool is_terminating) Line 182\tC++\n \tft2font_d.cp312-win_amd64.pyd!dllmain_crt_dispatch(HINSTANCE__ * const instance, const unsigned long reason, void * const reserved) Line 220\tC++\n \tft2font_d.cp312-win_amd64.pyd!dllmain_dispatch(HINSTANCE__ * const instance, const unsigned long reason, void * const reserved) Line 293\tC++\n \tft2font_d.cp312-win_amd64.pyd!_DllMainCRTStartup(HINSTANCE__ * const instance, const unsigned long reason, void * const reserved) Line 335\tC++\n \tntdll.dll!00007ff84667ef6a()\tUnknown\n \tntdll.dll!00007ff84657b2e3()\tUnknown\n \tntdll.dll!00007ff8465e027f()\tUnknown\n \tntdll.dll!00007ff8465def8e()\tUnknown\n \tkernel32.dll!00007ff8447a17ab()\tUnknown\n \tucrtbased.dll!00007fff08e6219b()\tUnknown\n \tucrtbased.dll!00007fff08e6214f()\tUnknown\n \tucrtbased.dll!00007fff08e62456()\tUnknown\n \tpython_d.exe!__scrt_common_main_seh() Line 295\tC++\n \tpython_d.exe!__scrt_common_main() Line 331\tC++\n \tpython_d.exe!wmainCRTStartup(void * __formal) Line 17\tC++\n \tkernel32.dll!00007ff84478dda7()\tUnknown\n \tntdll.dll!00007ff8465dee4c()\tUnknown\n```\n\nIt seems the enums map is deleted in scalar destructor at exit, far too late for python, and the decref crashes because of it.\n\nAs a workaround, since the object is not properly deleted anyways,\nyou can replace the line of _enums.h:\n`auto enums = std::unordered_map\u003cstd::string, py::object>{};`\nby\n`auto& enums = *new std::unordered_map\u003cstd::string, py::object>{};`\nSo no delete attempt is done, and the problem disappears\n\nCode changed in 3.11, so i suppose this only affects 3.10.x\n\n### Code for reproduction\n\n```Python\npython_d -c \"import matplotlib\"\n```\n\n### Actual outcome\n\nFatal Python error: _PyInterpreterState_GET: the function must be called with the GIL held, after Python initialization and before Python finalization, but the GIL is released (the current Python thread state is NULL)\nPython runtime state: finalizing (tstate=0x00007ffbe152fca0)\n\n### Expected outcome\n\nProcess imports matplotlib and finished without a GIL error\n\n### Additional information\n\n_No response_\n\n### Operating system\n\nWINdows 11\n\n### Matplotlib Version\n\n3.10.9\n\n### Matplotlib Backend\n\nbackend independant\n\n### Python version\n\n3.12.4 debug build\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\nfrom source (.tar.gz)","author":{"url":"https://github.com/bartoli","@type":"Person","name":"bartoli"},"datePublished":"2026-10-20T13:01:37Z","url":"https://github.com/matplotlib/matplotlib/issues/32509"}
| 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:d3f600e0-3ff1-3a48-f3b1-c46498916a44 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D47C:D37F7:EF0CEF:13FC5B0:6B064EA3 |
| html-safe-nonce | 119dff6128ee029b6964aa532f8d1190eead13edb1181ece981681371194e392 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENDdDOkQzN0Y3OkVGMENFRjoxM0ZDNUIwOjZCMDY0RUEzIiwidmlzaXRvcl9pZCI6IjU4MDQ2NjMyNDQ1MzA3OTgyNDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 40f03e6c93db6adde717c4a0dcb309ebb88671200ae0475f9f322122c491c029 |
| hovercard-subject-tag | issue:5942107918 |
| 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/matplotlib/matplotlib/32509/issue_layout |
| twitter:image | https://opengraph.githubassets.com/543ec3cff6faac6029b2ee1eb01d96a8d1672374ce2839a09afcadd04637bf0c/matplotlib/matplotlib/issues/32509 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/543ec3cff6faac6029b2ee1eb01d96a8d1672374ce2839a09afcadd04637bf0c/matplotlib/matplotlib/issues/32509 |
| og:image:alt | Bug summary I'm building a full debug Python environment (Python 3.12.4, numpy 2.4.6, pybind 3.1, contourpy 1.3.3, MPL 3.10.9) It seems that when MPL has been imported, the python interpreter shutd... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bartoli |
| hostname | github.com |
| expected-hostname | github.com |
| None | 772b6997ca4daa0428dd49a25d76052e765555ae560fe9c88517eb828bbd861e |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| 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 | f1f9a08f7c769a37f1dfc18ad43d463c222a7eea |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width