Hello,<br><br>I've wrote a program in pyqt4, that should redirect the
output of another program to a QTextEdit. Sometime the program crashes
as soon as I start a thread executing the second program with
subprocess.Popen().<br>
I used gdb:<br>(gdb) run TestThread.py <br>Starting program: /usr/bin/python TestThread.py<br>[Thread debugging using libthread_db enabled]<br>[New Thread 0xb7f036c0 (LWP 5001)]<br>[New Thread 0xb5a69b90 (LWP 5003)]<br><br>
Program received signal SIGSEGV, Segmentation fault.<br>[Switching to Thread 0xb7f036c0 (LWP 5001)]<br>0xb6be8802 in ?? () from /usr/lib/libQtGui.so.4<br><br>(gdb) bt<br>#0 0xb6be8802 in ?? () from /usr/lib/libQtGui.so.4<br>
#1 0xb6be12a5 in ?? () from /usr/lib/libQtGui.so.4<br>#2 0xb6be1b32 in QTextEngine::itemize () from /usr/lib/libQtGui.so.4<br>#3 0xb6be93c8 in QTextLayout::beginLayout () from /usr/lib/libQtGui.so.4<br>#4 0xb6c296eb in ?? () from /usr/lib/libQtGui.so.4<br>
#5 0xb6c3039f in ?? () from /usr/lib/libQtGui.so.4<br>#6 0xb6c2ec7a in ?? () from /usr/lib/libQtGui.so.4<br>#7 0xb6c2f186 in ?? () from /usr/lib/libQtGui.so.4<br>#8 0xb6c3166c in ?? () from /usr/lib/libQtGui.so.4<br>
#9 0xb6c31710 in ?? () from /usr/lib/libQtGui.so.4<br>
#10 0xb6c31902 in ?? () from /usr/lib/libQtGui.so.4<br>#11 0xb6c31d41 in ?? () from /usr/lib/libQtGui.so.4<br>#12 0xb6bfede5 in QTextDocument::setPageSize () from /usr/lib/libQtGui.so.4<br>#13 0xb6e39523 in ?? () from /usr/lib/libQtGui.so.4<br>
#14 0xb6e39d92 in QTextEdit::resizeEvent () from /usr/lib/libQtGui.so.4<br>#15 0xb73dfe3b in ?? () from /usr/lib/python2.6/dist-<div id=":fq" class="ii gt">packages/PyQt4/QtGui.so<br>#16 0xb69d8956 in QWidget::event () from /usr/lib/libQtGui.so.4<br>
#17 0xb6db2993 in QFrame::event () from /usr/lib/libQtGui.so.4<br>#18 0xb6e5294f in QAbstractScrollArea::viewportEvent ()<br> from /usr/lib/libQtGui.so.4<br>#19 0xb73dd2fc in ?? () from /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so<br>
#20 0xb6e54f55 in ?? () from /usr/lib/libQtGui.so.4<br>#21 0xb7bcdc5a in QCoreApplicationPrivate::sendThroughObjectEventFilters ()<br>---Type <return> to continue, or q <return> to quit---<br> from /usr/lib/libQtCore.so.4<br>
#22 0xb6981e7a in QApplicationPrivate::notify_helper ()<br> from /usr/lib/libQtGui.so.4<br>#23 0xb698a282 in QApplication::notify () from /usr/lib/libQtGui.so.4<br>#24 0xb76593f3 in ?? () from /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so<br>
#25 0xb7bcea3b in QCoreApplication::notifyInternal ()<br> from /usr/lib/libQtCore.so.4<br>#26 0xb6a181b6 in QWidgetPrivate::setGeometry_sys ()<br> from /usr/lib/libQtGui.so.4<br>#27 0xb69d7788 in QWidget::setGeometry () from /usr/lib/libQtGui.so.4<br>
#28 0xb6e52f08 in QAbstractScrollAreaPrivate::layoutChildren ()<br> from /usr/lib/libQtGui.so.4<br>#29 0xb6e5363e in QAbstractScrollArea::event () from /usr/lib/libQtGui.so.4<br>#30 0xb6e3cd0e in QTextEdit::event () from /usr/lib/libQtGui.so.4<br>
#31 0xb73def2d in ?? () from /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so<br>#32 0xb6981e9c in QApplicationPrivate::notify_helper ()<br> from /usr/lib/libQtGui.so.4<br>#33 0xb698a282 in QApplication::notify () from /usr/lib/libQtGui.so.4<br>
#34 0xb76593f3 in ?? () from /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so<br>#35 0xb7bcea3b in QCoreApplication::notifyInternal ()<br> from /usr/lib/libQtCore.so.4<br>#36 0xb69d7540 in QWidget::setContentsMargins () from /usr/lib/libQtGui.so.4<br>
#37 0xb6db268c in QFrame::setFrameRect () from /usr/lib/libQtGui.so.4<br>---Type <return> to continue, or q <return> to quit---<br>#38 0xb6e532ee in QAbstractScrollAreaPrivate::layoutChildren ()<br> from /usr/lib/libQtGui.so.4<br>
#39 0xb6e533bd in QAbstractScrollAreaPrivate::_q_showOrHideScrollBars ()<br> from /usr/lib/libQtGui.so.4<br>#40 0xb6e399d5 in ?? () from /usr/lib/libQtGui.so.4<br>#41 0xb6e3b61f in QTextEdit::qt_metacall () from /usr/lib/libQtGui.so.4<br>
#42 0xb73e0020 in ?? () from /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so<br>#43 0xb7be4ca8 in QMetaObject::activate () from /usr/lib/libQtCore.so.4<br>#44 0xb7be5932 in QMetaObject::activate () from /usr/lib/libQtCore.so.4<br>
#45 0xb6bce7a3 in QTextControl::documentSizeChanged ()<br> from /usr/lib/libQtGui.so.4<br>#46 0xb6bd5547 in QTextControl::qt_metacall () from /usr/lib/libQtGui.so.4<br>#47 0xb7bdd8fb in QMetaCallEvent::placeMetaCall () from /usr/lib/libQtCore.so.4<br>
#48 0xb7bdf3a0 in QObject::event () from /usr/lib/libQtCore.so.4<br>#49 0xb6bce514 in QTextControl::event () from /usr/lib/libQtGui.so.4<br>#50 0xb6981e9c in QApplicationPrivate::notify_helper ()<br> from /usr/lib/libQtGui.so.4<br>
#51 0xb698a19e in QApplication::notify () from /usr/lib/libQtGui.so.4<br>#52 0xb76593f3 in ?? () from /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so<br>#53 0xb7bcea3b in QCoreApplication::notifyInternal ()<br> from /usr/lib/libQtCore.so.4<br>
#54 0xb7bcf695 in QCoreApplicationPrivate::sendPostedEvents ()<br> from /usr/lib/libQtCore.so.4<br>---Type <return> to continue, or q <return> to quit---<br>#55 0xb7bcf88d in QCoreApplication::sendPostedEvents ()<br>
from /usr/lib/libQtCore.so.4<br>#56 0xb7bfa7ef in ?? () from /usr/lib/libQtCore.so.4<br>#57 0xb78f8b88 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0<br>#58 0xb78fc0eb in ?? () from /usr/lib/libglib-2.0.so.0<br>
#59 0xb78fc268 in g_main_context_iteration () from /usr/lib/libglib-2.0.so.0<br>#60 0xb7bfa438 in QEventDispatcherGlib::processEvents ()<br> from /usr/lib/libQtCore.so.4<br>#61 0xb6a23365 in ?? () from /usr/lib/libQtGui.so.4<br>
#62 0xb7bcd06a in QEventLoop::processEvents () from /usr/lib/libQtCore.so.4<br>#63 0xb7bcd4aa in QEventLoop::exec () from /usr/lib/libQtCore.so.4<br>#64 0xb7bcf959 in QCoreApplication::exec () from /usr/lib/libQtCore.so.4<br>
#65 0xb6981d17 in QApplication::exec () from /usr/lib/libQtGui.so.4<br>#66 0xb7659ef6 in ?? () from /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so<br>#67 0x080de562 in PyEval_EvalFrameEx (f=0x9ff689c, throwflag=0)<br> at ../Python/ceval.c:3706<br>
#68 0x080e00b8 in PyEval_EvalCodeEx (co=0xb7ea9260, globals=0xb7ee70b4, <br> locals=0xb7ee70b4, args=0x0, argcount=0, kws=0x0, kwcount=0, defs=0x0, <br> defcount=0, closure=0x0) at ../Python/ceval.c:2968<br>#69 0x080e0217 in PyEval_EvalCode (co=0xb7ea9260, globals=0xb7ee70b4, <br>
locals=0xb7ee70b4) at ../Python/ceval.c:522<br>#70 0x080fe0e1 in PyRun_FileExFlags (fp=0x9ffbfa8, <br> filename=0xbf8f4a3a "TestThread.py", start=257, globals=0xb7ee70b4, <br>---Type <return> to continue, or q <return> to quit---<br>
locals=0xb7ee70b4, closeit=1, flags=0xbf8f2938)<br> at ../Python/pythonrun.c:1335<br>#71 0x080fe43a in PyRun_SimpleFileExFlags (fp=0x9ffbfa8, <br> filename=0xbf8f4a3a "TestThread.py", closeit=1, flags=0xbf8f2938)<br>
at ../Python/pythonrun.c:931<br>#72 0x0805c882 in Py_Main (argc=1, argv=0xbf8f2a04) at ../Modules/main.c:599<br>#73 0x0805b972 in main (argc=127, argv=0x0) at ../Modules/python.c:23<br><br>here is the code, that reproduce the error:<br>
<br>import time, sys, os, subprocess, select, threading<br>from PyQt4 import QtCore, QtGui<br><br>class TestGUI(QtGui.QWidget):<br> def __init__(self, parent = None):<br> QtGui.QWidget.__init__(self, parent)<br> self.Widgets()<br>
self.Connections()<br> <br> def Widgets(self):<br> self.txtBox = QtGui.QTextEdit()<br> self.btnStart = QtGui.QPushButton("Start Thread")<br> self.txtBox.setReadOnly(True)<br> <br> hb = QtGui.QHBoxLayout()<br>
hb.addWidget(self.txtBox)<br> hb.addWidget(self.btnStart)<br> <br> self.setLayout(hb)<br> <br> def Connections(self):<br> self.connect(self.btnStart, QtCore.SIGNAL("clicked()"), self.startThread)<br>
<br> def startThread(self):<br> self.thread = TestThread(self, cmd = ["ls", "/home/hao"], box = self.txtBox)<br> self.thread.start()<br> self.btnStart.setDisabled(True)<br><br>class TestThread(threading.Thread):<br>
def __init__(self, parent, cmd = None, box = None):<br> threading.Thread.__init__(self)<br> self.cmd = cmd<br> self.box = box<br> <br> def run(self):<br> self.prog = subprocess.Popen(self.cmd, bufsize = 1, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)<br>
self.rFile = select.select([self.prog.stdout], [], [], 3600)<br> line = ""<br><br> for line in self.rFile[0][0]:<br> self.box.append(line)<br><br>if __name__ == "__main__":<br> app = QtGui.QApplication(sys.argv)<br>
t = TestGUI()<br> t.show()<br> sys.exit(app.exec_())<br><br>hao<br></div>