[PyQt] Freezes and crashes with signal autoconnection

Hans-Peter Jansen hpj at urpla.net
Thu Dec 3 10:20:39 GMT 2009

On Thursday 03 December 2009, 02:09:36 Christian Roche wrote:
> Phil Thompson-5 wrote:
> > Either way people need a small, self-contained example that
> > demonstrates the problem.
> Hi Phil,
> I think I've been able to isolate a small piece of code that consistently
> reproduces the problem.  http://old.nabble.com/file/p26619445/main.py

This does NOT qualify as a small piece of code, because:
 - it's convoluted code (e.g. it's not obvious, which part runs threaded)
 - you're doing hard to track things with QUrls (this is, where it crashes)

> This piece of code  displays a gray rectangle on my system and
> systematically crashes when I click on it.  My config is as follows:
> qt-4.5.3-9.fc11.i586.rpm
> PyQt4-4.5.4-1.fc11.i586.rpm
> sip-4.8.2-1.fc11.i586.rpm
> I'd be very interested in understanding what's wrong here because i've
> been strugling for weeks with incomprehensible crashes that seem to come
> out of nowhere and I've not the single clue what's going on.

Your clue stick is called gdb, but you need to prepare your system 
accordingly, e.g. need to install debuginfo packages of Qt, sip and PyQt 
beforehand. Then run:

gdb python -ex 'set args main.py' -ex run

Click on the image, and:

Starting program: main.py
[Thread debugging using libthread_db enabled]
[New Thread 0xb5c85b90 (LWP 4686)]
[Thread 0xb5c85b90 (LWP 4686) exited]

Program received signal SIGSEGV, Segmentation fault.
0xb783c49a in QUrl (this=0xb5305630, url=@0xb530b3ec) at io/qurl.cpp:3907
3907        if (!url.isEmpty())
Current language:  auto; currently c++
(gdb) bt
#0  0xb783c49a in QUrl (this=0xb5305630, url=@0xb530b3ec) at io/qurl.cpp:3907
#1  0xb7a436bc in init_QUrl (sipArgs=0x8145ecc, sipArgsParsed=0xbfffb6f0) at sipQtCoreQUrl.cpp:2576
#2  0xb799edc7 in sipSimpleWrapper_init (self=0x815e8cc, args=0x8145ecc, kwds=0x0) at siplib.c:7945
#3  0xb7ebc9b5 in type_call (type=<value optimized out>, args=0x8145ecc, kwds=0x0) at Objects/typeobject.c:745
#4  0xb7e6bc1c in PyObject_Call (func=0x80dcd9c, arg=0x8145ecc, kw=0x0) at Objects/abstract.c:2487
#5  0xb7ef6d20 in PyEval_EvalFrameEx (f=0xb530b734, throwflag=0) at Python/ceval.c:3890
#6  0xb7ef623d in PyEval_EvalFrameEx (f=0xb530b15c, throwflag=0) at Python/ceval.c:3765
#7  0xb7ef623d in PyEval_EvalFrameEx (f=0xb530aff4, throwflag=0) at Python/ceval.c:3765
#8  0xb7efbb9b in PyEval_EvalCodeEx (co=0xb7c3b3c8, globals=0xb7c7902c, locals=0x0, args=0xb7c463f8, argcount=2, 
    kws=0x0, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:2942
#9  0xb7e90a29 in function_call (func=0xb7bbce2c, arg=0xb7c463ec, kw=0x0) at Objects/funcobject.c:524
#10 0xb7e6bc1c in PyObject_Call (func=0xb7bbce2c, arg=0xb7c463ec, kw=0x0) at Objects/abstract.c:2487
#11 0xb7e799fe in instancemethod_call (func=0xb7bbce2c, arg=0xb7c463ec, kw=0x0) at Objects/classobject.c:2579
#12 0xb7e6bc1c in PyObject_Call (func=0xb7c2984c, arg=0x8145d0c, kw=0x0) at Objects/abstract.c:2487
#13 0xb7ef474f in PyEval_CallObjectWithKeywords (func=0xb7c2984c, arg=0x8145d0c, kw=0x0) at Python/ceval.c:3548
#14 0xb79a0933 in sip_api_call_method (isErr=0x0, method=0xb7c2984c, fmt=0xb723e007 "D") at siplib.c:1534
#15 0xb6d57679 in sipVH_QtGui_27 (sipGILState=PyGILState_UNLOCKED, sipMethod=0xb7c2984c, a0=0xbfffcc48)
    at sipQtGuicmodule.cpp:7057
#16 0xb6fe4239 in sipQListView::mouseReleaseEvent (this=0x820cce8, a0=0xbfffcc48) at sipQtGuiQListView.cpp:763
#17 0xb62b7363 in QWidget::event (this=0x820cce8, event=0xbfffcc48) at kernel/qwidget.cpp:7554
#18 0xb66479b3 in QFrame::event (this=0x820cce8, e=0xbfffcc48) at widgets/qframe.cpp:559
#19 0xb66e6c7f in QAbstractScrollArea::viewportEvent (this=0x820cce8, e=0xb5300001)
    at widgets/qabstractscrollarea.cpp:962
#20 0xb6799567 in QAbstractItemView::viewportEvent (this=0x820cce8, event=0xbfffcc48)
    at itemviews/qabstractitemview.cpp:1476
#21 0xb6fdd70f in sipQListView::viewportEvent (this=0x820cce8, a0=0xbfffcc48) at sipQtGuiQListView.cpp:1371
#22 0xb66e9285 in QAbstractScrollAreaFilter::eventFilter (this=0x820e250, o=0x820cb10, e=0xbfffcc48)
    at widgets/qabstractscrollarea_p.h:100
#23 0xb7882b0a in QCoreApplicationPrivate::sendThroughObjectEventFilters (this=0x8196878, receiver=0x820cb10, 
    event=0xbfffcc48) at kernel/qcoreapplication.cpp:726
#24 0xb626074a in QApplicationPrivate::notify_helper (this=0x8196878, receiver=0x820cb10, e=0xbfffcc48)
    at kernel/qapplication.cpp:4061
#25 0xb62693d1 in QApplication::notify (this=0x8196858, receiver=0x820cb10, e=0xbfffcc48)
    at kernel/qapplication.cpp:3767
#26 0xb71bb4ce in sipQApplication::notify (this=0x8196858, a0=0x820cb10, a1=0xbfffcc48) at sipQtGuiQApplication.cpp:309
#27 0xb78838fb in QCoreApplication::notifyInternal (this=0x8196858, receiver=0x820cb10, event=0xbfffcc48)
    at kernel/qcoreapplication.cpp:610
#28 0xb626843e in QApplicationPrivate::sendMouseEvent (receiver=0x820cb10, event=0xbfffcc48, alienWidget=0x820cb10, 
    nativeWidget=0x81e8090, buttonDown=0xb6ac9a20, lastMouseReceiver=@0xb6ac9a24)
    at ../../src/corelib/kernel/qcoreapplication.h:216
#29 0xb62d8696 in QETWidget::translateMouseEvent (this=0x81e8090, event=0xbfffe2dc) at kernel/qapplication_x11.cpp:4409
#30 0xb62d7a6d in QApplication::x11ProcessEvent (this=0x8196858, event=0xbfffe2dc) at kernel/qapplication_x11.cpp:3428
#31 0xb63015ca in x11EventSourceDispatch (s=0x819deb0, callback=0, user_data=0x0)
    at kernel/qguieventdispatcher_glib.cpp:146
#32 0xb76b4948 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0

eh voilà, your code crashes in the QUrl ctor. Easy, isn't it. This procedure
should help you to isolate your issue. 

Doing silly things in Qt results in this behavior, and PyQt cannot not protect
you here, while it adds some obstacles inherited from Python semantics (e.g. 
lifetime issues). OTOH, it's a small price to pay for using the most efficient 
and versatile toolkit out there with Python.

Good luck,

More information about the PyQt mailing list