[Bug]: 3.10 debug build crashes on interpreter exit
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
Línea de trabajo
Start with _enums.h and trace the lifetime of the enums map used by ft2font; the report includes a reproduction command: python_d -c "import matplotlib". Check how that map is cleaned up during interpreter shutdown and compare the reported behavior between 3.10 and 3.11. Done means importing Matplotlib in a Python 3.12.4 debug build exits without a GIL error.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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 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)
Python runtime state: finalizing (tstate=0x00007ffbe152fca0)
In release builds, this does not occur, but I suppose it's because there are less asserts on GIL state at shutdown.
When debugging, the stack is
KernelBase.dll!00007ff843eb3122() Unknown
python312_d.dll!fatal_error_exit(int status) Line 2778 C
python312_d.dll!fatal_error(int fd, int header, const char * prefix, const char * msg, int status) Line 2959 C
python312_d.dll!_Py_FatalErrorFunc(const char * func, const char * msg) Line 2975 C
python312_d.dll!_PyInterpreterState_GET() Line 131 C
python312_d.dll!_Py_DECREF_DecRefTotal() Line 240 C
ft2font_d.cp312-win_amd64.pyd!Py_DECREF(const char * filename, int lineno, _object * op) Line 688 C++
ft2font_d.cp312-win_amd64.pyd!Py_XDECREF(_object * op) Line 798 C++
ft2font_d.cp312-win_amd64.pyd!pybind11::handle::dec_ref() Line 300 C++
ft2font_d.cp312-win_amd64.pyd!pybind11::object::~object() Line 395 C++
ft2font_d.cp312-win_amd64.pyd!std::pair<std::string const ,pybind11::object>::~pair<std::string const ,pybind11::object>() C++
ft2font_d.cp312-win_amd64.pyd!std::pair<std::string const ,pybind11::object>::`scalar deleting destructor'(unsigned int) C++
ft2font_d.cp312-win_amd64.pyd!std::_Default_allocator_traits<std::allocator<std::_List_node<std::pair<std::string const ,pybind11::object>,void *>>>::destroy<std::pair<std::string const ,pybind11::object>>(std::allocator<std::_List_node<std::pair<std::string const ,pybind11::object>,void *>> & __formal, std::pair<std::string const ,pybind11::object> * const _Ptr) Line 741 C++
ft2font_d.cp312-win_amd64.pyd!std::_List_node<std::pair<std::string const ,pybind11::object>,void *>::_Freenode<std::allocator<std::_List_node<std::pair<std::string const ,pybind11::object>,void *>>>(std::allocator<std::_List_node<std::pair<std::string const ,pybind11::object>,void *>> & _Al, std::_List_node<std::pair<std::string const ,pybind11::object>,void *> * _Ptr) Line 318 C++
ft2font_d.cp312-win_amd64.pyd!std::_List_node<std::pair<std::string const ,pybind11::object>,void *>::_Free_non_head<std::allocator<std::_List_node<std::pair<std::string const ,pybind11::object>,void *>>>(std::allocator<std::_List_node<std::pair<std::string const ,pybind11::object>,void *>> & _Al, std::_List_node<std::pair<std::string const ,pybind11::object>,void *> * _Head) Line 329 C++
ft2font_d.cp312-win_amd64.pyd!std::list<std::pair<std::string const ,pybind11::object>,std::allocator<std::pair<std::string const ,pybind11::object>>>::_Tidy() Line 1519 C++
ft2font_d.cp312-win_amd64.pyd!std::list<std::pair<std::string const ,pybind11::object>,std::allocator<std::pair<std::string const ,pybind11::object>>>::~list<std::pair<std::string const ,pybind11::object>,std::allocator<std::pair<std::string const ,pybind11::object>>>() Line 1063 C++
ft2font_d.cp312-win_amd64.pyd!std::_Hash<std::_Umap_traits<std::string,pybind11::object,std::_Uhash_compare<std::string,std::hash<std::string>,std::equal_to<std::string>>,std::allocator<std::pair<std::string const ,pybind11::object>>,0>>::~_Hash<std::_Umap_traits<std::string,pybind11::object,std::_Uhash_compare<std::string,std::hash<std::string>,std::equal_to<std::string>>,std::allocator<std::pair<std::string const ,pybind11::object>>,0>>() C++
ft2font_d.cp312-win_amd64.pyd!std::unordered_map<std::string,pybind11::object,std::hash<std::string>,std::equal_to<std::string>,std::allocator<std::pair<std::string const ,pybind11::object>>>::~unordered_map<std::string,pybind11::object,std::hash<std::string>,std::equal_to<std::string>,std::allocator<std::pair<std::string const ,pybind11::object>>>() C++
ft2font_d.cp312-win_amd64.pyd!p11x::`anonymous namespace'::`dynamic atexit destructor for 'enums''() C++
ucrtbased.dll!00007fff08e62b99() Unknown
ucrtbased.dll!00007fff08e625c5() Unknown
ucrtbased.dll!00007fff08e62717() Unknown
ucrtbased.dll!00007fff08e62d44() Unknown
ft2font_d.cp312-win_amd64.pyd!__scrt_dllmain_uninitialize_c() Line 398 C++
> ft2font_d.cp312-win_amd64.pyd!dllmain_crt_process_detach(const bool is_terminating) Line 182 C++
ft2font_d.cp312-win_amd64.pyd!dllmain_crt_dispatch(HINSTANCE__ * const instance, const unsigned long reason, void * const reserved) Line 220 C++
ft2font_d.cp312-win_amd64.pyd!dllmain_dispatch(HINSTANCE__ * const instance, const unsigned long reason, void * const reserved) Line 293 C++
ft2font_d.cp312-win_amd64.pyd!_DllMainCRTStartup(HINSTANCE__ * const instance, const unsigned long reason, void * const reserved) Line 335 C++
ntdll.dll!00007ff84667ef6a() Unknown
ntdll.dll!00007ff84657b2e3() Unknown
ntdll.dll!00007ff8465e027f() Unknown
ntdll.dll!00007ff8465def8e() Unknown
kernel32.dll!00007ff8447a17ab() Unknown
ucrtbased.dll!00007fff08e6219b() Unknown
ucrtbased.dll!00007fff08e6214f() Unknown
ucrtbased.dll!00007fff08e62456() Unknown
python_d.exe!__scrt_common_main_seh() Line 295 C++
python_d.exe!__scrt_common_main() Line 331 C++
python_d.exe!wmainCRTStartup(void * __formal) Line 17 C++
kernel32.dll!00007ff84478dda7() Unknown
ntdll.dll!00007ff8465dee4c() Unknown
It seems the enums map is deleted in scalar destructor at exit, far too late for python, and the decref crashes because of it.
As a workaround, since the object is not properly deleted anyways,
you can replace the line of _enums.h:
auto enums = std::unordered_map<std::string, py::object>{};
by
auto& enums = *new std::unordered_map<std::string, py::object>{};
So no delete attempt is done, and the problem disappears
Code changed in 3.11, so i suppose this only affects 3.10.x
Code for reproduction
python_d -c "import matplotlib"
Actual outcome
Fatal 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)
Python runtime state: finalizing (tstate=0x00007ffbe152fca0)
Expected outcome
Process imports matplotlib and finished without a GIL error
Additional information
No response
Operating system
WINdows 11
Matplotlib Version
3.10.9
Matplotlib Backend
backend independant
Python version
3.12.4 debug build
Jupyter version
No response
Installation
from source (.tar.gz)
- Lenguaje dominante
- Python
- Estrellas
- 23.5k
- Forks
- 8.6k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 64
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de matplotlib/matplotlib
-
[Bug]: Saving a NonUniformImage with bbox_inches="tight" raises TypeError when extent is omittedAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
matplotlib/matplotlib#32707 ·
Los mantenedores suelen responder en 1 día
-
[Bug]: withTickedStroke raises ValueError when the line contains NaNPosiblemente ocupada @RjyavardhanSingh la tomó hace 3 días. Abiertofirst-contribution topic: path handling
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
matplotlib/matplotlib#32689 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
[Bug]: Constrained layout raises ZeroDivisionError when the first height/width ratio is zeroPosiblemente ocupada @yqtian-se la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
matplotlib/matplotlib#32684 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
[Bug]: twin axes ignore the navigation opt-outsPosiblemente ocupada @NaumanRafay la tomó hace 36 días. Abiertotopic: toolbar
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
matplotlib/matplotlib#32528 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
[Bug]: macOS font discovery raises KeyError('_items') for an incomplete system_profiler font recordAbiertofirst-contribution OS: Apple status: needs clarification topic: text/fonts
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
matplotlib/matplotlib#32328 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de matplotlib/matplotlib
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
nael5x/creative-ai#130 ·
-
Make the "%" unit spacing the same in the web and in A10Posiblemente ocupada @kragent66-glitch la tomó hoy. Abiertobug good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
maiychrus25/OpenTea-DX-OS#226 · 1 comentario ·
-
ci severity: low
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
TMHSDigital/Spackle#205 ·
Los mantenedores suelen responder en 1 día
-
pkg:lgm type:chore upstream-gaussx
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
jejjohnson/pyrox#610 ·
Los mantenedores suelen responder en 1 día