Segmentation fault after migrating to PySide2 from PyQT5
-
We have recently migrated our app from PyQT5 to PySide2 and without any QT related code changes, we started observing significant amount of segmentation faults.
Being new to QT development env in Python can anyone please guide on how to debug this error.
Env: Fedora OS, Python 3.6.8, PySide2 5.15.2.1Below are the things that I have tried.
- Ran the python using gdb and executed the backtrace command after segfault. But I did not understand what to do with that as it pointed out to the so library files.
- Reviewed if any of the QT GUI code is getting invoked via normal threads but it is not the case as we are relying on signals and slots and this used to work without any issues in the PYQT5.
So please help in understanding how to debug this issue.
-
@lokeshdotp said in Segmentation fault after migrating to PySide2 from PyQT5:
But I did not understand what to do with that
You can post it here, maybe somebody will be able to see what the crash is about
-
@jsulm
Here is the stacktrace#0 0x00000000021b3f90 in ?? ()
#1 0x00007fffe8bb7986 in Shiboken::BindingManager::runDeletionInMainThread() () from /PathToBin/venv/lib/python3.6/site-packages/shiboken2/libshiboken2.abi3.so.5.15
#2 0x00007fffe8ba0a4a in mainThreadDeletionHandler () from /PathToBin/venv/lib/python3.6/site-packages/shiboken2/libshiboken2.abi3.so.5.15
#3 0x00007ffff7df988c in Py_MakePendingCalls () at Python/ceval.c:526
#4 Py_MakePendingCalls () at Python/ceval.c:474
#5 0x00007ffff7dfb32d in _PyEval_EvalFrameDefault (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:1182
#6 0x00007ffff7df9a83 in _PyFunction_FastCall (co=co@entry=0x7fffe9209c90, args=<optimized out>, nargs=2, globals=<optimized out>) at Python/ceval.c:4933
#7 0x00007ffff7e03044 in _PyFunction_FastCallDict (func=func@entry=0x7fff941da7b8, args=<optimized out>, args@entry=0x7fffffffca00, nargs=nargs@entry=2, kwargs=kwargs@entry=0x0) at Python/ceval.c:5042
#8 0x00007ffff7d26691 in _PyObject_FastCallDict (func=func@entry=0x7fff941da7b8, args=args@entry=0x7fffffffca00, nargs=nargs@entry=2, kwargs=kwargs@entry=0x0) at Objects/abstract.c:2310
#9 0x00007ffff7d267bd in _PyObject_Call_Prepend (func=0x7fff941da7b8, obj=0x7fffffffca00, args=0x7fff644d55c0, kwargs=0x0) at Objects/abstract.c:2373
#10 0x00007ffff7d26467 in PyObject_Call (func=0x7fff80520048, args=<optimized out>, kwargs=<optimized out>) at Objects/abstract.c:2261
#11 0x00007fffa7489d8f in PySide::SignalManager::callPythonMetaMethod(QMetaMethod const&, void**, _object*, bool) () from /PathToBin/venv/lib/python3.6/site-packages/PySide2/libpyside2.abi3.so.5.15
#12 0x00007fffa748a14c in PySide::SignalManager::qt_metacall(QObject*, QMetaObject::Call, int, void**) () from /PathToBin/venv/lib/python3.6/site-packages/PySide2/libpyside2.abi3.so.5.15
#13 0x00007fffa5db9da3 in QObject::event(QEvent*) () from /PathToBin/venv/lib/python3.6/site-packages/PySide2/Qt/lib/libQt5Core.so.5
#14 0x00007fffa1bbdc3d in QObjectWrapper::event(QEvent*) () from /PathToBin/venv/lib/python3.6/site-packages/PySide2/QtCore.abi3.so
#15 0x00007fffa6d7743c in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /PathToBin/venv/lib/python3.6/site-packages/PySide2/Qt/lib/libQt5Widgets.so.5
#16 0x00007fffa6d7df20 in QApplication::notify(QObject*, QEvent*) () from /PathToBin/venv/lib/python3.6/site-packages/PySide2/Qt/lib/libQt5Widgets.so.5
#17 0x00007fffa7854395 in QApplicationWrapper::notify(QObject*, QEvent*) () from /PathToBin/venv/lib/python3.6/site-packages/PySide2/QtWidgets.abi3.so
#18 0x00007fffa5d8a808 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () from /PathToBin/venv/lib/python3.6/site-packages/PySide2/Qt/lib/libQt5Core.so.5
#19 0x00007fffa5d8d882 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () from /PathToBin/venv/lib/python3.6/site-packages/PySide2/Qt/lib/libQt5Core.so.5
#20 0x00007fffa5de6b33 in postEventSourceDispatch(GSource*, int ()(void), void*) () from /PathToBin/venv/lib/python3.6/site-packages/PySide2/Qt/lib/libQt5Core.so.5
#21 0x00007fffa2d2e78f in g_main_dispatch (context=0x7fff84005040) at ../glib/gmain.c:3309
#22 g_main_context_dispatch (context=0x7fff84005040) at ../glib/gmain.c:3974
#23 0x00007fffa2d2eb18 in g_main_context_iterate (context=context@entry=0x7fff84005040, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at ../glib/gmain.c:4047
#24 0x00007fffa2d2ebe3 in g_main_context_iteration (context=0x7fff84005040, may_block=1) at ../glib/gmain.c:4108
#25 0x00007fffa5de61cc in QEventDispatcherGlib::processEvents(QFlagsQEventLoop::ProcessEventsFlag) () from /PathToBin/venv/lib/python3.6/site-packages/PySide2/Qt/lib/libQt5Core.so.5
#26 0x00007fffa5d8921a in QEventLoop::exec(QFlagsQEventLoop::ProcessEventsFlag) () from /PathToBin/venv/lib/python3.6/site-packages/PySide2/Qt/lib/libQt5Core.so.5
#27 0x00007fffa5d921d3 in QCoreApplication::exec() () from /PathToBin/venv/lib/python3.6/site-packages/PySide2/Qt/lib/libQt5Core.so.5
#28 0x00007fffa7851e08 in Sbk_QApplicationFunc_exec () from /PathToBin/venv/lib/python3.6/site-packages/PySide2/QtWidgets.abi3.so
#29 0x00007ffff7d77d9e in _PyCFunction_FastCallDict (func_obj=func_obj@entry=0x7fffa158d1b0, args=0x7fff8049ca40, nargs=0, kwargs=kwargs@entry=0x0) at Objects/methodobject.c:192
#30 0x00007ffff7d78051 in _PyCFunction_FastCallKeywords (func=func@entry=0x7fffa158d1b0, stack=<optimized out>, nargs=nargs@entry=0, kwnames=kwnames@entry=0x0) at Objects/methodobject.c:294
#31 0x00007ffff7dfa974 in call_function (pp_stack=pp_stack@entry=0x7fffffffd3e0, oparg=<optimized out>, kwnames=kwnames@entry=0x0) at Python/ceval.c:4851
#32 0x00007ffff7dff5e1 in _PyEval_EvalFrameDefault (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:3335
#33 0x00007ffff7df9a83 in _PyFunction_FastCall (co=<optimized out>, args=<optimized out>, nargs=nargs@entry=1, globals=<optimized out>) at Python/ceval.c:4933
#34 0x00007ffff7dfaa4c in fast_function (kwnames=0x0, nargs=1, stack=<optimized out>, func=0x7fff941da510) at Python/ceval.c:4968
#35 call_function (pp_stack=pp_stack@entry=0x7fffffffd570, oparg=<optimized out>, kwnames=kwnames@entry=0x0) at Python/ceval.c:4872
#36 0x00007ffff7dff5e1 in _PyEval_EvalFrameDefault (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:3335
#37 0x00007ffff7df9a83 in _PyFunction_FastCall (co=<optimized out>, args=<optimized out>, nargs=nargs@entry=2, globals=<optimized out>) at Python/ceval.c:4933
#38 0x00007ffff7dfaa4c in fast_function (kwnames=0x0, nargs=2, stack=<optimized out>, func=0x7fff93bc46a8) at Python/ceval.c:4968
#39 call_function (pp_stack=pp_stack@entry=0x7fffffffd700, oparg=<optimized out>, kwnames=kwnames@entry=0x0) at Python/ceval.c:4872
#40 0x00007ffff7dff5e1 in _PyEval_EvalFrameDefault (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:3335
#41 0x00007ffff7df9a83 in _PyFunction_FastCall (co=<optimized out>, args=<optimized out>, nargs=nargs@entry=0, globals=<optimized out>) at Python/ceval.c:4933
#42 0x00007ffff7dfaa4c in fast_function (kwnames=0x0, nargs=0, stack=<optimized out>, func=0x7fff93bc6488) at Python/ceval.c:4968
#43 call_function (pp_stack=pp_stack@entry=0x7fffffffd890, oparg=<optimized out>, kwnames=kwnames@entry=0x0) at Python/ceval.c:4872
#44 0x00007ffff7dff5e1 in _PyEval_EvalFrameDefault (f=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:3335
#45 0x00007ffff7dfa47b in _PyEval_EvalCodeWithName (_co=_co@entry=0x7fffea8989c0, globals=globals@entry=0x7fffea8da120, locals=locals@entry=0x7fffea8da120, args=args@entry=0x0, argcount=argcount@entry=0, kwnames=kwnames@entry=0x0,
kwargs=0x0, kwcount=0, kwstep=2, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0, name=0x0, qualname=0x0) at Python/ceval.c:4166
#46 0x00007ffff7dfaa9e in PyEval_EvalCodeEx (_co=_co@entry=0x7fffea8989c0, globals=globals@entry=0x7fffea8da120, locals=locals@entry=0x7fffea8da120, args=args@entry=0x0, argcount=argcount@entry=0, kws=kws@entry=0x0, kwcount=0, defs=0x0,
defcount=0, kwdefs=0x0, closure=0x0) at Python/ceval.c:4187
#47 0x00007ffff7dfaacb in PyEval_EvalCode (co=co@entry=0x7fffea8989c0, globals=globals@entry=0x7fffea8da120, locals=locals@entry=0x7fffea8da120) at Python/ceval.c:731
#48 0x00007ffff7e2c501 in run_mod (arena=0x7fffea8f32e8, flags=0x7fffffffdbac, locals=0x7fffea8da120, globals=0x7fffea8da120, filename=0x7fffea7198f0, mod=0x4c21f0) at Python/pythonrun.c:1025
#49 PyRun_FileExFlags (fp=fp@entry=0x474b10, filename_str=filename_str@entry=0x7fffea78ffe0 "main.py", start=start@entry=257, globals=globals@entry=0x7fffea8da120, locals=locals@entry=0x7fffea8da120, closeit=closeit@entry=1,
--Type <RET> for more, q to quit, c to continue without paging--
flags=0x7fffffffdbac) at Python/pythonrun.c:978
#50 0x00007ffff7e2c68b in PyRun_SimpleFileExFlags (fp=fp@entry=0x474b10, filename=<optimized out>, closeit=closeit@entry=1, flags=flags@entry=0x7fffffffdbac) at Python/pythonrun.c:419
#51 0x00007ffff7e2cb2c in PyRun_AnyFileExFlags (fp=fp@entry=0x474b10, filename=<optimized out>, closeit=closeit@entry=1, flags=flags@entry=0x7fffffffdbac) at Python/pythonrun.c:81
#52 0x00007ffff7e459d1 in run_file (p_cf=0x7fffffffdbac, filename=0x406760 L"main.py", fp=0x474b10) at Modules/main.c:340
#53 Py_Main (argc=argc@entry=3, argv=argv@entry=0x4052a0) at Modules/main.c:810
#54 0x0000000000401232 in main (argc=3, argv=<optimized out>) at ./Programs/python.c:69 -
@lokeshdotp
I don't think anyone is going to be able to tell anything from the stack trace.libshiboken
is to do with the bindings between Python/PySide2 and C++, that's all I know.Don't know what "QT GUI code is getting invoked via normal threads" means, but if you are using threads that is always a potential source of problems.
I suggest you need to find out what is happening at the Python/PySide2 level. You'll have to put in, say, some
print()
statements till you see where the crash happens, then work back from there. -
@lokeshdotp said in Segmentation fault after migrating to PySide2 from PyQT5:
#0 0x00000000021b3f90 in ?? ()
#1 0x00007fffe8bb7986 in Shiboken::BindingManager::runDeletionInMainThread() () from /PathToBin/venv/lib/python3.6/site-packages/shiboken2/libshiboken2.abi3.so.5.15Shiboken::BindingManager::runDeletionInMainThread():
void BindingManager::runDeletionInMainThread() { for (const DestructorEntry &e : m_d->deleteInMainThread) e.destructor(e.cppInstance); m_d->deleteInMainThread.clear(); }
Of the options for a functional call, my guess is that e.destructor() is stack frame #0. Presuming the naming is accurate, I suspect a double deletion. Python and Qt object lifetime management sometimes collide unless extra precautions are taken. https://www.riverbankcomputing.com/static/Docs/PyQt5/gotchas.html#garbage-collection discusses the topic at a high level. Perhaps PySide has slightly different object lifetime tracking.
Connecting a debug print statement to QObject::destroyed() has helped me diagnose similar situations with PyQt programs.
-
@lokeshdotp
To see when aQObject
(and anything derived from it) is destroyed, as @jeremy_k said, the following should work from Python:objectInstance.destroyed.connect(lambda: print("Name:", self.objectName())) # or maybe, don't know: objectInstance.destroyed.connect(lambda: print("Name:", objectInstance.objectName()))
(I hope this will work, but not sure if you would fall foul of https://stackoverflow.com/questions/16842955/widgets-destroyed-signal-is-not-fired-pyqt.)
Something like this may help you track down a double deletion.
-
I have had the same error but with another library "libQt5Qml.so.5". I have tried various alternatives, and in my case, that error occurred when I executed a function in QML, which was supposed to create a custom component previously created in another directory, inside main.qml. In the end, the only thing that solved the problem was migrating to QT6. In my case, I was using PySide2, so switching from PySide2 to PySide6 solved the problem. Try using QT6 instead of QT5. Good Luck