PySide6 Crash upon exit after QUiLoader::load with custom widgets
-
Running PySide6 any version, Python 3.10/3.11 on Windows 11.
Running the example code, as is, as can be found in;
https://doc.qt.io/qtforpython/tutorials/basictutorial/uifiles.html#option-b-loading-it-directly
i.e. copy/paste example code in main.py and mainwindow.uimain.py crashes upon exit when the 'custom widget' mechanism is used.
For the 'custom widget' mechanism refer to;
https://doc.qt.io/qtforpython/tutorials/basictutorial/uifiles.html#custom-widgets-in-qt-designerTo deploy the custom widget mechanism do the following;
- Add a PYSIDE_DESIGNER_PLUGINS environment variable and set it with the path to a folder holding,
- a register*.py file (can be empty) holding the custom widget registration code
main.py now crashes upon exit. Post mortem analysis reveals;
Unhandled exception thrown: read access violation. tstate was nullptr. > python311.dll!import_get_module(_ts * tstate, _object * name) Line 314 python311.dll!PyImport_GetModule(_object * name) Line 1764 python311.dll!wait_for_thread_shutdown(_ts * tstate) Line 2894 python311.dll!Py_FinalizeEx() Line 1767Without the environment variable or register*.py file or both, main.py does not crash.
With PySide2, main.py does not crash.
-
Can this be caused by the PySidePlugin.dll.PyDesignerCustomWidgets::PyDesignerCustomWidgets which does a Py_Initialize?
This is fine in an application embedding Python, i.e. Qt Designer but not in a Python interpreter, i.e. in a Python script.
-
Fixed, see; https://bugreports.qt.io/browse/PYSIDE-2222
-
It looks like this is a known issue with PySide6. You should try using the latest version of PySide6, which should fix the issue. You can also try using the Qt for Python 5.15.2 release, which should also fix the issue. If neither of those solutions work, then you should report the issue to the Qt for Python team.