[PyKDE] PyEval_RestoreThread Error

Michael Andrews mandrews at mandrews.org
Thu Aug 21 13:07:01 BST 2003


I don't know if this is a Python, Qt, or PyQt issue.  I thought I'd
start with PyQt and we'll see where it leads.  I am trying to build a
new Python/Qt environment consisting of:
  Python 2.3, Qt-3.2.0, sip-3.8, and PyQt-3.8
When I run the bug_test.py script below and then immediately press the
Quit button, python dumps core with the following error:

  Fatal Python error: PyEval_RestoreThread: NULL tstate

I have reproduced the problem under HPUX 11 and Redhat Linux-9, and the 
'application' works fine under Python 2.2.3, Qt 3.1.2, sip-3.6, and
PyQt-3.6.

The problem appears to be the fact that my UIMainC class (the
controller) has a member which is the AppClass and the AppClass has a
member which is the controller.  If I remove the UIMainC.app everything
works.

Any suggestions on how to proceed?
-- 
Michael Andrews <mandrews at mandrews.org>

bug_test.py
===========
#!/usr/bin/env python

import sys
from qt import *

class UIMain(QDialog):
    "Simple View Class"
    def __init__(self,parent = None,name = None,modal = 0,fl = 0):
        QDialog.__init__(self,parent,name,modal,fl)

        if not name:
            self.setName("UIMain")

        self.PrintButton = QPushButton(self,"PrintButton")
        self.PrintButton.setGeometry(QRect(70,260,201,91))

        self.QuitButton = QPushButton(self,"QuitButton")
        self.QuitButton.setGeometry(QRect(330,250,221,101))

        self.AppDataLineEdit = QLineEdit(self,"AppDataLineEdit")
        self.AppDataLineEdit.setGeometry(QRect(100,90,171,41))

        self.languageChange()

        self.resize(QSize(600,482).expandedTo(self.minimumSizeHint()))
        self.clearWState(Qt.WState_Polished)

        self.connect(self.PrintButton,SIGNAL("clicked()"),self.Print)
        self.connect(self.QuitButton,SIGNAL("clicked()"),\
                     self,SLOT("close()"))

    def languageChange(self):
        self.setCaption(self.__tr("UIMain"))
        self.PrintButton.setText(self.__tr("Print"))
        self.QuitButton.setText(self.__tr("Quit"))

    def Print(self):
        print "UIMain.Print(): Not implemented yet"

    def __tr(self,s,c = None):
        return qApp.translate("UIMain",s,c)

class UIMainC(UIMain):
    "Simple Controller Class"
    def __init__(self,parent = None,name = None,fl = 0, app=None):
        UIMain.__init__(self,parent,name,fl)
        self.app = app
        self.AppDataLineEdit.setText(self.app.text)

    # public slots
    def Print(self):
        self.app.text = str(self.AppDataLineEdit.text())
        self.app.Print()

class AppClass:
    """Main application class
    Contains: Main controller widget
              Application Data and slots as members of this class"""
    def __init__(self,args):
        self.text = "Application Data"
        self.gui = QApplication(args)
       
QObject.connect(self.gui,SIGNAL("lastWindowClosed()"),self.gui,SLOT("quit()"))
        self.gui_w = UIMainC(app=self)
        self.gui.setMainWidget(self.gui_w)
        
    def execute(self):
        "Execute the application"
        self.gui_w.show()
        self.gui.exec_loop()

    def Print(self):
        print self.text
        return
        
def main(argv=['']):
    app = AppClass(argv)
    app.execute()
        
if __name__ == "__main__":
    main()






More information about the PyQt mailing list