PyQt4 Segmentation fault

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

PyQt4 Segmentation fault

hao1986
Hallo,

ich habe ein python programm geschrieben, welches mir die textausgabe vom einen anderen programm in einem qtextedit umleiten soll. das zweite programm rufe ich in einem thread mit subprocess.Popen auf. nach einigen versuchen bin ich draufgekommen, QTextEdit den fehler produziert. es kann sein, dass der fehler nicht immer kommt!
ich habe das ganze auch mit einem QThread, bekomme aber den selben fehler.

hier ist der pyqt4 code, der den fehler reproduziert:

import time, sys, os, subprocess, select, threading
from PyQt4 import QtCore, QtGui

class TestGUI(QtGui.QWidget):
  def __init__(self, parent = None):
    QtGui.QWidget.__init__(self, parent)
    self.Widgets()
    self.Connections()
 
  def Widgets(self):
    self.txtBox = QtGui.QTextEdit()
    self.btnStart = QtGui.QPushButton("Start Thread")
    self.txtBox.setReadOnly(True)
   
    hb = QtGui.QHBoxLayout()
    hb.addWidget(self.txtBox)
    hb.addWidget(self.btnStart)
   
    self.setLayout(hb)
 
  def Connections(self):
    self.connect(self.btnStart, QtCore.SIGNAL("clicked()"), self.startThread)
 
  def startThread(self):
    self.thread = TestThread(self, cmd = ["ls", "/home/hao"], box = self.txtBox)
    self.thread.start()
    self.btnStart.setDisabled(True)

class TestThread(threading.Thread):
  def __init__(self, parent, cmd = None,  box = None):
    threading.Thread.__init__(self)
    self.cmd = cmd
    self.box = box
 
  def run(self):
    self.prog = subprocess.Popen(self.cmd, bufsize = 1, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
    self.rFile = select.select([self.prog.stdout], [], [], 3600)
    line = ""

    for line in self.rFile[0][0]:
      self.box.append(line)

if __name__ == "__main__":
  app = QtGui.QApplication(sys.argv)
  t = TestGUI()
  t.show()
  sys.exit(app.exec_())

mit gdb bekomme ich folgenden Fehlermeldung:

(gdb) run TestThread.py
Starting program: /usr/bin/python TestThread.py
[Thread debugging using libthread_db enabled]
[New Thread 0xb7dd56c0 (LWP 7011)]
[New Thread 0xb58d1b90 (LWP 7012)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb7dd56c0 (LWP 7011)]
0xb6ab60f1 in QTextEngine::shapeTextWithHarfbuzz () from /usr/lib/libQtGui.so.4

(gdb) bt
#0  0xb6ab60f1 in QTextEngine::shapeTextWithHarfbuzz ()
   from /usr/lib/libQtGui.so.4
#1  0xb6ab67ea in QTextEngine::shapeText () from /usr/lib/libQtGui.so.4
#2  0xb6ab6c38 in QTextEngine::shape () from /usr/lib/libQtGui.so.4
#3  0xb6abe631 in QTextLine::layout_helper () from /usr/lib/libQtGui.so.4
#4  0xb6abf1b0 in QTextLine::setLineWidth () from /usr/lib/libQtGui.so.4
#5  0xb6afc1c5 in ?? () from /usr/lib/libQtGui.so.4
#6  0xb6b0239f in ?? () from /usr/lib/libQtGui.so.4
#7  0xb6b00c7a in ?? () from /usr/lib/libQtGui.so.4
#8  0xb6b01186 in ?? () from /usr/lib/libQtGui.so.4
#9  0xb6b0366c in ?? () from /usr/lib/libQtGui.so.4
#10 0xb6b03710 in ?? () from /usr/lib/libQtGui.so.4
#11 0xb6b03902 in ?? () from /usr/lib/libQtGui.so.4
#12 0xb6b03d41 in ?? () from /usr/lib/libQtGui.so.4
#13 0xb6ad0de5 in QTextDocument::setPageSize () from /usr/lib/libQtGui.so.4
#14 0xb6d0b523 in ?? () from /usr/lib/libQtGui.so.4
#15 0xb6d0bd92 in QTextEdit::resizeEvent () from /usr/lib/libQtGui.so.4
#16 0xb72b1e3b in ?? () from /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so
#17 0xb68aa956 in QWidget::event () from /usr/lib/libQtGui.so.4
#18 0xb6c84993 in QFrame::event () from /usr/lib/libQtGui.so.4
#19 0xb6d2494f in QAbstractScrollArea::viewportEvent ()
   from /usr/lib/libQtGui.so.4
#20 0xb72af2fc in ?? () from /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so
---Type <return> to continue, or q <return> to quit---
#21 0xb6d26f55 in ?? () from /usr/lib/libQtGui.so.4
#22 0xb7a9fc5a in QCoreApplicationPrivate::sendThroughObjectEventFilters ()
   from /usr/lib/libQtCore.so.4
#23 0xb6853e7a in QApplicationPrivate::notify_helper ()
   from /usr/lib/libQtGui.so.4
#24 0xb685c282 in QApplication::notify () from /usr/lib/libQtGui.so.4
#25 0xb752b3f3 in ?? () from /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so
#26 0xb7aa0a3b in QCoreApplication::notifyInternal ()
   from /usr/lib/libQtCore.so.4
#27 0xb68ea1b6 in QWidgetPrivate::setGeometry_sys ()
   from /usr/lib/libQtGui.so.4
#28 0xb68a9788 in QWidget::setGeometry () from /usr/lib/libQtGui.so.4
#29 0xb6d24f08 in QAbstractScrollAreaPrivate::layoutChildren ()
   from /usr/lib/libQtGui.so.4
#30 0xb6d2563e in QAbstractScrollArea::event () from /usr/lib/libQtGui.so.4
#31 0xb6d0ed0e in QTextEdit::event () from /usr/lib/libQtGui.so.4
#32 0xb72b0f2d in ?? () from /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so
#33 0xb6853e9c in QApplicationPrivate::notify_helper ()
   from /usr/lib/libQtGui.so.4
#34 0xb685c282 in QApplication::notify () from /usr/lib/libQtGui.so.4
#35 0xb752b3f3 in ?? () from /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so
#36 0xb7aa0a3b in QCoreApplication::notifyInternal ()
   from /usr/lib/libQtCore.so.4
---Type <return> to continue, or q <return> to quit---
#37 0xb68a9540 in QWidget::setContentsMargins () from /usr/lib/libQtGui.so.4
#38 0xb6c8468c in QFrame::setFrameRect () from /usr/lib/libQtGui.so.4
#39 0xb6d252ee in QAbstractScrollAreaPrivate::layoutChildren ()
   from /usr/lib/libQtGui.so.4
#40 0xb6d253bd in QAbstractScrollAreaPrivate::_q_showOrHideScrollBars ()
   from /usr/lib/libQtGui.so.4
#41 0xb6d0b9d5 in ?? () from /usr/lib/libQtGui.so.4
#42 0xb6d0d61f in QTextEdit::qt_metacall () from /usr/lib/libQtGui.so.4
#43 0xb72b2020 in ?? () from /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so
#44 0xb7ab6ca8 in QMetaObject::activate () from /usr/lib/libQtCore.so.4
#45 0xb7ab7932 in QMetaObject::activate () from /usr/lib/libQtCore.so.4
#46 0xb6aa07a3 in QTextControl::documentSizeChanged ()
   from /usr/lib/libQtGui.so.4
#47 0xb6aa7547 in QTextControl::qt_metacall () from /usr/lib/libQtGui.so.4
#48 0xb7aaf8fb in QMetaCallEvent::placeMetaCall () from /usr/lib/libQtCore.so.4
#49 0xb7ab13a0 in QObject::event () from /usr/lib/libQtCore.so.4
#50 0xb6aa0514 in QTextControl::event () from /usr/lib/libQtGui.so.4
#51 0xb6853e9c in QApplicationPrivate::notify_helper ()
   from /usr/lib/libQtGui.so.4
#52 0xb685c19e in QApplication::notify () from /usr/lib/libQtGui.so.4
#53 0xb752b3f3 in ?? () from /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so
#54 0xb7aa0a3b in QCoreApplication::notifyInternal ()
   from /usr/lib/libQtCore.so.4
---Type <return> to continue, or q <return> to quit---
#55 0xb7aa1695 in QCoreApplicationPrivate::sendPostedEvents ()
   from /usr/lib/libQtCore.so.4
#56 0xb7aa188d in QCoreApplication::sendPostedEvents ()
   from /usr/lib/libQtCore.so.4
#57 0xb7acc7ef in ?? () from /usr/lib/libQtCore.so.4
#58 0xb77cab88 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#59 0xb77ce0eb in ?? () from /usr/lib/libglib-2.0.so.0
#60 0xb77ce268 in g_main_context_iteration () from /usr/lib/libglib-2.0.so.0
#61 0xb7acc438 in QEventDispatcherGlib::processEvents ()
   from /usr/lib/libQtCore.so.4
#62 0xb68f5365 in ?? () from /usr/lib/libQtGui.so.4
#63 0xb7a9f06a in QEventLoop::processEvents () from /usr/lib/libQtCore.so.4
#64 0xb7a9f4aa in QEventLoop::exec () from /usr/lib/libQtCore.so.4
#65 0xb7aa1959 in QCoreApplication::exec () from /usr/lib/libQtCore.so.4
#66 0xb6853d17 in QApplication::exec () from /usr/lib/libQtGui.so.4
#67 0xb752bef6 in ?? () from /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so
#68 0x080de562 in PyEval_EvalFrameEx (f=0x958a624, throwflag=0)
    at ../Python/ceval.c:3706
#69 0x080e00b8 in PyEval_EvalCodeEx (co=0xb7d7b2f0, globals=0xb7db90b4,
    locals=0xb7db90b4, args=0x0, argcount=0, kws=0x0, kwcount=0, defs=0x0,
    defcount=0, closure=0x0) at ../Python/ceval.c:2968
#70 0x080e0217 in PyEval_EvalCode (co=0xb7d7b2f0, globals=0xb7db90b4,
    locals=0xb7db90b4) at ../Python/ceval.c:522
---Type <return> to continue, or q <return> to quit---
#71 0x080fe0e1 in PyRun_FileExFlags (fp=0x9539cc0,
    filename=0xbf9c6733 "TestThread.py", start=257, globals=0xb7db90b4,
    locals=0xb7db90b4, closeit=1, flags=0xbf9c4ea8)
    at ../Python/pythonrun.c:1335
#72 0x080fe43a in PyRun_SimpleFileExFlags (fp=0x9539cc0,
    filename=0xbf9c6733 "TestThread.py", closeit=1, flags=0xbf9c4ea8)
    at ../Python/pythonrun.c:931
#73 0x0805c882 in Py_Main (argc=1, argv=0xbf9c4f74) at ../Modules/main.c:599
#74 0x0805b972 in main (argc=161064632, argv=0xb7b95a48)
    at ../Modules/python.c:23