[PyKDE] QThread run() method not being called when start() is executed (PyQt4/ Windows XP)

Tony Cappellini cappy2112 at gmail.com
Mon Mar 5 22:32:13 GMT 2007


Hello Phil,

> Fix your code or post your code.
> Sorry I can't give a more specific answer - a more specific question would
> help.

Not sure how more specific I could get. The run() method isn't being
invoked, and I don't know how to debug a thread issue.

As you requested, here's my code.

class ConvertThread(QThread):
  def __init__(self,main):
    QThread.__init__(self)
    self.main = main
    self.connect(self, SIGNAL('write'), self.main.write)

  def run(self):
    self.str = ''
    script=open('nm2g2.py').read()
    globs = globals()
    exec 'from nm2g2 import *' in globs
    logging = globs['logging']
    logging.basicConfig(stream=self, format='%(message)s')
    main(['nm2g2.py','-v0']+self.files)
    logging.critical('Conversion finished.')
    self.exit(0)

  def write(self, s):
    self.str += s

  def flush(self):
    self.emit(SIGNAL('write'), self.str)
    self.str = ''


class NM2G2G(QMainWindow):
    def __init__(self, parent=None):
        QMainWindow.__init__(self, parent)
        self.ui=Ui_NM2G2G()
        self.ui.setupUi(self)
        self.connect(self.ui._StartConversion, SIGNAL("clicked()"),
self._ launchG2oolsApplication)

        self.convert = ConvertThread(self)

  def _launchG2oolsApplication(self):
        self.convert.files =[]
        for fn in self._TargetFilesToConvert:
           self.convert.files.append(fn)

        self.convert.start()

def write(self, s):
        self.ui.PatchConversionBrowser.insertPlainText(s)
        self.ui.PatchConversionBrowser.ensureCursorVisible()





Background info:

The gui launches another python app. That app converts files from one
format to another format, resulting in an output file (with a specific
file extension) being generated for each input file. I can run that
python app from the cmd line, and the input file are converted,
indicating the target app functionality.

My GUI is a slight adaptation of another GUI written by someone else.
My GUI suffers from "freezing/hanging" while the target app is
running. The other GUI does not, because it is using a Thread to write
to the GUI. So, I'm trying to adapt my gui, so it doesn't hang while
the target app is running.

Both GUIs call the same target application to convert the files. My
GUI uses the exact same ConvertThread() class as the GUI which works,
but it seems as though run() is not being called in my GUI.

self.ui._StartConversion is the button which is clicked which results
in self.convert.start()
getting called.


The reasons I speculate that run() isn't getting called

1. No output files are generated by the target application (the Python
app being launched by the GUI)

2. I've set breakpoints where self.convert.start() is called, and in
NM2G2G.write() self.convert.start() is being executed, but
NM2G2G.write() never gets called. Since NM2G2G.write() isn't getting
called, I'm speculating that run() is never being called.

If I can elaborate on anything else, let me know.




More information about the PyQt mailing list