PyQt4 applications crash at exit

Bug #561303 reported by Xavier Aragon on 2010-04-12
142
This bug affects 24 people
Affects Status Importance Assigned to Milestone
PyLotRO
Undecided
Unassigned
python-qt4 (Ubuntu)
Undecided
Unassigned
Lucid
High
Clint Byrum

Bug Description

[Test Case]
Try any of the basic examples in python-qt4-doc:

jss@jss-laptop:$ python /usr/share/doc/python-qt4-doc/examples/richtext/syntaxhighlighter.py
...
Segmentation fault
Fixed versions should work properly.

[Regression Potential]
While this is an update from upstream, it is a very tiny actual change (view the diff with 'filterdiff -x doc/* -x sip/*').

---------------

Binary package hint: python-qt4

Package python-qt4 (python bindings for qt4) seems to be broken in Lucid beta 2. Many PyQt4 applications crash at exit, which can be easily reproduced by running some of the example applications available in package python-qt4-doc. For example, run ' python /usr/share/doc/python-qt4-doc/examples/dialogs/findfiles.py'. When the dialog is closed, the application dies with segmentation fault.

The python-qt4 version in Lucid beta 2 is 4.7.2-0ubuntu1. The PyQt4 mailing list has several recent reports about this kind of crashes with PyQt4 version 4.7.2, due to some changes in the way objects are deleted at exit. The following message on the mailing list indicates that a fixed version 4.7.3 is to be released shortly. I hope the fixed version will be included in Lucid, or if not possible then revert back to some older version that does not crash applications at exit.

  http://www.riverbankcomputing.com/pipermail/pyqt/2010-April/026385.html

Related branches

Xavier Aragon (xarax-lp) on 2010-04-12
tags: added: lucid
nlcom (nlcom) wrote :

I can confirm this bug in Lucid.

Sybren Stüvel (sybren-stuvel) wrote :

http://article.gmane.org/gmane.comp.python.pyqt-pykde/18961 indicates that version 4.7.3 indeed fixes this issue.

Please fix this issue, as it's quite bothersome for me. The crash doesn't just occur at the end of the PyQt process, but when the QApplication is deleted. In my unittests this happens for every test, to ensure inter-test insulation, but due to the segmentation fault the test runner dies while testing.

Sybren Stüvel (sybren-stuvel) wrote :

By the way, it seems to be quite a small change from 4.7.2 to 4.7.3. The changelog can be found at http://www.riverbankcomputing.co.uk/static/Downloads/PyQt4/ChangeLog

Sybren Stüvel (sybren-stuvel) wrote :

Just a heads-up: the segfault-at-exit can also be caused by instantiating multiple QApplication instances. This confuses Qt/PyQt and can cause a segfault at the destruction of the second QApplication instance. I've blogged about this (including the solution) at http://stuvel.eu/archive/127/pyqt-segfault-solved

Umang Varma (umang) wrote :

Sybren, is that a work around or a good-practice? I don't seem to set QtGui.qApp anywhere in my application at all. However, I'm using 4.7.3 now and I don't encounter this problem at all. If it is a good practice, I will set QtGui.qApp to the current QApplication instance.

Also, in your blog you've said:

> After a lot of puzzling I found out that QtCore.qApp needs to refer to the running QApplication instance,

While your code uses QtGui.qApp. That's a typo I presume?

Sybren Stüvel (sybren-stuvel) wrote :

Personally I would classify this as a workaround. IMO not following a good-practice should not result in a segfault.

My usage of QApplication is rather unique, in that I create and destroy multiple QApplication instances sequentially, in the same process. You don't need to bother with setting QtGui.qApp if your process stops when the QApplication instance stops.

Maybe setting QtGui.qApp = None after each QApplication has shut down is enough to solve the segfault. However, I chose to be thorough and set it always. It's only two lines of extra code.

QtCore.qApp is indeed a typo, the code is correct in using QtGui.qApp. Thanks for pointing that out.

Umang Varma (umang) wrote :

Thanks for that. I've changed my code to look like this now. I'll test it with 4.7.2 later and see if I still get a segfault.

    QtGui.qApp = app
    app.exec_()
    QtGui.qApp = None

Jeremy Sanders (jeremysanders) wrote :

Note that even the simplest PyQt programs segmentation fault with the current PyQt version. Try any of the basic examples in python-qt4-doc:

jss@jss-laptop:$ python /usr/share/doc/python-qt4-doc/examples/richtext/syntaxhighlighter.py
...
Segmentation fault

This problem stops my application (Veusz) saving its setting on exit. Please fix this - Fedora took a couple of days to release a new version.

DaVince (vincentbeers) wrote :

PyQt 4.7.3 seems to be mostly a bugfix release. Therefore, does it stand any chance to get included to the package repository as an update? The segfault quite annoys me.

Peter Silva (peter-bsqt) wrote :

I can't run the profiler because the segfault happens before it writes the profile output.
really annoying.

The problem seems to be fixed in maverick RC amd64.

Changed in python-qt4 (Ubuntu):
status: New → Fix Released
Alan Jackson (ajackson-bcs) wrote :

Fix released in python-qt4 that should solve the problem in PyLotRO

Changed in pylotro:
status: New → Fix Released
Israel G. Lugo (ilugo) wrote :

The problem still exists in Lucid Lynx, which is a long term support release. Will the problem be fixed in Lucid as well, or will those of us who use the long term support release have to give up on any expectations of support?

Rohan Garg (rohangarg) wrote :

I'll take this up after 31st December if no one has poked it by then, nominated for lucid for now

Changed in python-qt4 (Ubuntu):
milestone: none → ubuntu-10.04.2
Israel G. Lugo (ilugo) wrote :

Thank you. I had opened bug #694541 in the meantime, to track the Lucid-specific part. Please feel free to close that if you believe it best to solve the problem here.

Israel G. Lugo (ilugo) wrote :

Hello; just checking to see if someone had had the chance to pick up on this.

Randy Syring (rsyring) wrote :

+1 for Lucid...thanks.

Barry (mr-scada) wrote :

Would love a Lucid port for this :-)

description: updated
Clint Byrum (clint-fewbar) wrote :

I uploaded cshorler's fix to lucid-proposed, it awaits review by the SRU team.

Changed in python-qt4 (Ubuntu Lucid):
status: New → Triaged
importance: Undecided → High
Scott Kitterman (kitterman) wrote :

The full diff isn't needed and contains new features that aren't the sort we generally accept for an SRU. The relevant bit of the diff to fix this problem is:

=== modified file 'sip/QtGui/qapplication.sip'
--- sip/QtGui/qapplication.sip revid:<email address hidden>
+++ sip/QtGui/qapplication.sip revid:<email address hidden>
@@ -1,4 +1,4 @@
-// qapplication.sip generated by MetaSIP on Wed Mar 17 18:29:25 2010
+// qapplication.sip generated by MetaSIP on Fri Apr 16 11:32:08 2010
 //
 // This file is part of the QtGui Python extension module.
 //
@@ -596,13 +596,17 @@
 %End
     virtual ~QApplication();
 %MethodCode
- // Make sure all top level widgets are deleted before the QApplication. This
- // is a typical cause of crashes (or at least strange behaviour) when an
- // application terminates.
+ // Make sure all top level widgets are not owned by Python and so won't be
+ // destroyed by the garbage collector after QApplication is destroyed.
         QWidgetList tlw = QApplication::topLevelWidgets();

         for (int i = 0; i < tlw.count(); ++i)
- delete tlw.at(i);
+ {
+ PyObject *sw = sipGetPyObject(tlw.at(i), sipType_QWidget);
+
+ if (sw)
+ sipTransferTo(sw, 0);
+ }

         // Handle all other QObject instances that we want to make sure are deleted
         // before the QApplication is deleted.

Please don't do the full version update. Do a new one with this as a patch.

Changed in python-qt4 (Ubuntu Lucid):
status: Triaged → In Progress
assignee: nobody → Clint Byrum (clint-fewbar)

Hello Xavier, or anyone else affected,

Accepted python-qt4 into lucid-proposed. The package will build now and be available at http://launchpad.net/ubuntu/+source/python-qt4/4.7.2-0ubuntu1.1 in a few hours and then in the -proposed repository. Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you please change the bug tag from verification-needed to verification-done. If it does not, change the tag to verification-failed. In either case details of your testing will help us make a better decision. Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance!

Changed in python-qt4 (Ubuntu Lucid):
status: In Progress → Fix Committed
tags: added: verification-needed
Clint Byrum (clint-fewbar) wrote :

I'm not actually able to reproduce the original issue. The example programs all work fine without this update.

Scott Kitterman (kitterman) wrote :

This seems to work fine and is obviously more correct than what's there now.

tags: added: verification-done
removed: verification-needed

The verification of this Stable Release Update has completed successfully and the package has now been released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regresssions.

Launchpad Janitor (janitor) wrote :

This bug was fixed in the package python-qt4 - 4.7.2-0ubuntu1.1

---------------
python-qt4 (4.7.2-0ubuntu1.1) lucid-proposed; urgency=low

  * d/p/lp-561303.diff: Cherry pick fix from 4.7.3 to stop
    crashes. (LP: #561303)
 -- Clint Byrum <email address hidden> Fri, 22 Jun 2012 10:59:44 -0700

Changed in python-qt4 (Ubuntu Lucid):
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Duplicates of this bug

Other bug subscribers