[PyQt] Crash in frozen PyQt5 app

Phil Thompson phil at riverbankcomputing.com
Fri Aug 30 09:11:27 BST 2013


On Fri, 30 Aug 2013 15:13:29 +1200, Glenn Ramsey <gr at componic.co.nz>
wrote:
> Hi,
> 
> When running the following test app on OSX (10.8.4, PyQt 5.1 snapshot +
Qt
> 5.1.1)
> 
>
https://github.com/pyinstaller/pyinstaller/blob/develop/tests/interactive/test_pyqt5_qml.py
> 
> I get a crash when it is frozen using PyInstaller but not when it is not
> frozen. 
> The crash occurs in QQuickView::setSource(...)
> 
> A stack trace for a very similar test app is here
> http://pastebin.com/ZhqZFPxG
> 
> Inspecting it in the debugger shows that the cause of the crash is that 
> QCoreApplication::instance() returns 0 and in the stack trace shows the
> abort 
> caused by a Q_ASSERT that I put in to check that.
> 
> Any ideas about what could be happening here?

No, but a comment on the use of "global app" in the code...

The effect of that is to impose some order on the garbage collection of
Python objects. When main() returns the local objects get garbage collected
in an arbitrary order. If that order is wrong as far as Qt is concerned
then you get undefined behaviour or a crash. Specifying "app" as a global
means that it will get garbage collected later. Personally I never use a
main() function and put the code at the module level under "if __name__ ==
'__main__'". It should only be a few lines anyway.

Phil


More information about the PyQt mailing list