Priority: P2: Important
Affects Version/s: 1.2.2
Fix Version/s: 5.12.0
Environment:Ubuntu 16.04, qt-4.8.7, pyside 1.2.2
Commits:6bfbfd6edd0f9701664698768f9ec8d29f96a5bd (pyside-setup/5.12, 15.10.2018, 5.12), bfc7f380a0867044a1642181f2dc002ab88376c9 (pyside-setup/5.12)
Using Python threads inside a PySide application causes memory corruption, random crashes, deadlocks, asserts, etc.
To reproduce (on vanilla Ubuntu 16.04): crash1.py
Stack trace: [^stack1.txt]
Both import thread/threading and QThread Python threads are affected.
This bug means that Python threads cannot be used safely inside a PySide application at all.
The problem stems from the fact that the Python garbage collector run can be triggered by the Python interpreter on any Python thread and at any point in time.
The garbage collector calls into SbkDeallocWrapper which in turn calls the QWidget destructor (QWidget::~QWidget) on a secondary thread which causes memory corruption, crashes & deadlocks as QWidget methods must not be called from any secondary threads as per definition.
If you run a Qt debug build, you'll see the following assert:
Recommended fix: Defer de-allocation of QWidget C++ objects inside SbkDeallocWrapper to the main UI thread (e.g. via deleteLater or via tracking them in an internal list).
The suggested work-around to disable the Python garbage collector and only manually collect in the main UI thread is neither practical nor performant.
|For Gerrit Dashboard: PYSIDE-810|
|240311,14||Fix crash when garbage collecting in a non-GUI thread||5.12||pyside/pyside-setup||Status: MERGED||-2||0|
|240426,5||libshikoken: Refactor the Visitor class hierarchy||dev||pyside/pyside-setup||Status: MERGED||+2||0|