[PyQt] QtGui.QApplication() never returns

Joe Turpin joe.turpin at gmail.com
Mon Dec 14 15:14:53 GMT 2009


On Mon, Dec 14, 2009 at 9:15 AM, David Boddie <dboddie at trolltech.com> wrote:
> On Sat Dec 12 21:47:16 GMT 2009, Joe Turpin wrote:
>
>> I have a very basic python script file that looks like the following
>> (taken directly from an online tutorial):
>>
>>     #!/usr/bin/python
>>
>>     # simple.py
>>
>>     import sys
>>     from PyQt4 import QtGui
>>
>>     app = QtGui.QApplication(sys.argv)
>>
>>     widget = QtGui.QWidget()
>>     widget.resize(250, 150)
>>     widget.setWindowTitle('simple')
>>     widget.show()
>>
>>     sys.exit(app.exec_())
>>
>> The script runs to completion when I execute it under my regular user
>> account, but hangs when I execute it as root.. Using pdb I inserted a
>> set_trace() and found that it never returns from the call to
>> QtGui.QApplication(). Any ideas why this might be happening?
>
> Can you give us some more information about your system's configuration
> (operating system, versions of Python, Qt and PyQt) ...

OS = Fedora Core 12 / Linux 2.6.31.6-166.fc12.x86_64
Python = 2.6.2-2
Qt = 4.5.3-9
PyQt = 4.6.2-5

> ... and describe what
> happens in a bit more detail? For example, I presume that the window is
> shown when you run the script as root and that you close it as normal.
> Is that correct?

No. There is no window displayed. Nothing happens, so there's not much
to describe other than that the script makes the call to
QtGui.QApplication() and never returns from that call so that I have
to forcibly end the application by first suspending it via Ctrl+z and
then kill it via 'kill %1 && fg'.

>
> I guess you could try and run the whole thing using gdb to see where in
> Qt it is hanging, though that would require the debug version of Qt to be
> installed.
>
>  gdb python
>  set arg simple.py
>  r
>
>  ... some time later hit Ctrl-C and examine the backtrace ...
>  bt

Here's the result of that:

(gdb) set arg simple.py
(gdb) r
Starting program: /usr/bin/python simple.py
[Thread debugging using libthread_db enabled]
^C
Program received signal SIGINT, Interrupt.
0x000000330c20b04c in pthread_cond_wait@@GLIBC_2.3.2 () from
/lib64/libpthread.so.0
(gdb) bt
#0  0x000000330c20b04c in pthread_cond_wait@@GLIBC_2.3.2 () from
/lib64/libpthread.so.0
#1  0x0000003248859573 in ?? () from /usr/lib64/libQtCore.so.4
#2  0x00000032488550b5 in QMutex::lock() () from /usr/lib64/libQtCore.so.4
#3  0x0000003248e40229 in ?? () from /usr/lib64/libQtDBus.so.4
#4  0x000000330e20aeb1 in ?? () from /lib64/libdbus-1.so.3
#5  0x000000330e20ee80 in ?? () from /lib64/libdbus-1.so.3
#6  0x000000330e210e91 in ?? () from /lib64/libdbus-1.so.3
#7  0x000000330e210586 in dbus_connection_send_with_reply_and_block ()
from /lib64/libdbus-1.so.3
#8  0x000000330e20b268 in dbus_bus_register () from /lib64/libdbus-1.so.3
#9  0x000000330e20b6b6 in ?? () from /lib64/libdbus-1.so.3
#10 0x0000003248e121c2 in
QDBusConnection::connectToBus(QDBusConnection::BusType, QString
const&) ()
   from /usr/lib64/libQtDBus.so.4
#11 0x0000003248e1231c in ?? () from /usr/lib64/libQtDBus.so.4
#12 0x0000003248e12459 in QDBusConnection::sessionBus() () from
/usr/lib64/libQtDBus.so.4
#13 0x00007fffefd79477 in ?? () from /usr/lib64/kde4/plugins/styles/oxygen.so
#14 0x00007fffefd86acd in ?? () from /usr/lib64/kde4/plugins/styles/oxygen.so
#15 0x000000324a42c68e in QStyleFactory::create(QString const&) ()
from /usr/lib64/libQtGui.so.4
#16 0x000000324a193930 in QApplication::style() () from /usr/lib64/libQtGui.so.4
#17 0x000000324a1f445a in ?? () from /usr/lib64/libQtGui.so.4
#18 0x000000324a1fd9fd in ?? () from /usr/lib64/libQtGui.so.4
#19 0x000000324a193c63 in QApplicationPrivate::construct(_XDisplay*,
unsigned long, unsigned long) ()
   from /usr/lib64/libQtGui.so.4
#20 0x000000324a194bb1 in QApplication::QApplication(int&, char**,
int) () from /usr/lib64/libQtGui.so.4
#21 0x00007ffff0dc9e0e in ?? () from
/usr/lib64/python2.6/site-packages/PyQt4/QtGui.so
#22 0x00007ffff0dca0eb in ?? () from
/usr/lib64/python2.6/site-packages/PyQt4/QtGui.so
#23 0x00007ffff063f46e in PyDict_New () from
/usr/lib64/python2.6/site-packages/sip.so
#24 0x000000331cc99a78 in ?? () from /usr/lib64/libpython2.6.so.1.0
#25 0x000000331cc43b33 in PyObject_Call () from /usr/lib64/libpython2.6.so.1.0
#26 0x000000331ccdc58d in PyEval_EvalFrameEx () from
/usr/lib64/libpython2.6.so.1.0
#27 0x000000331ccde4e5 in PyEval_EvalCodeEx () from
/usr/lib64/libpython2.6.so.1.0
#28 0x000000331ccde5f2 in PyEval_EvalCode () from /usr/lib64/libpython2.6.so.1.0
#29 0x000000331ccf965c in ?? () from /usr/lib64/libpython2.6.so.1.0
#30 0x000000331ccf9730 in PyRun_FileExFlags () from
/usr/lib64/libpython2.6.so.1.0
#31 0x000000331ccfab0c in PyRun_SimpleFileExFlags () from
/usr/lib64/libpython2.6.so.1.0
#32 0x000000331cd07389 in Py_Main () from /usr/lib64/libpython2.6.so.1.0
#33 0x000000330ba1eb1d in __libc_start_main () from /lib64/libc.so.6
#34 0x0000000000400649 in _start ()

>
> An alternative would be to run the script using strace to see if it's hanging
> when trying to open some file or device:
>
>  strace python simple.py
>

Here's the tail end of the output from strace:

socket(PF_FILE, SOCK_STREAM, 0)         = 9
connect(9, {sa_family=AF_FILE, path=@"/tmp/dbus-MCrOTrRby1"}, 23) = 0
fcntl(9, F_GETFL)                       = 0x2 (flags O_RDWR)
fcntl(9, F_SETFL, O_RDWR|O_NONBLOCK)    = 0
fcntl(9, F_GETFD)                       = 0
fcntl(9, F_SETFD, FD_CLOEXEC)           = 0
geteuid()                               = 0
rt_sigaction(SIGPIPE, {SIG_IGN, [PIPE], SA_RESTORER|SA_RESTART,
0x330ba32730}, {SIG_IGN, [], SA_RESTORER, 0x330c20efa0}, 8) = 0
poll([{fd=9, events=POLLOUT}], 1, 0)    = 1 ([{fd=9, revents=POLLOUT}])
write(9, "\0", 1)                       = 1
write(9, "AUTH EXTERNAL 30\r\n", 18)    = 18
poll([{fd=9, events=POLLIN}], 1, -1)    = 1 ([{fd=9, revents=POLLIN}])
read(9, "OK 9449259164682c16d7bd238d4b264"..., 2048) = 37
poll([{fd=9, events=POLLOUT}], 1, -1)   = 1 ([{fd=9, revents=POLLOUT}])
write(9, "BEGIN\r\n", 7)                = 7
poll([{fd=9, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=9,
revents=POLLIN|POLLOUT|POLLHUP}])
read(9, "", 2048)                       = 0
close(9)                                = 0
futex(0xe40acc, FUTEX_WAIT_PRIVATE, 1, NULL


Thanks for the help Dave. FYI, this simple program is really just to
troubleshoot why the Maemo SDK installer won't run as root.

Thanks again,
Joe



More information about the PyQt mailing list