threading crashes application

Robert rmanx at gmx.de
Thu Mar 25 08:51:36 EST 2004


Hello List,

I have implemented an application in python 2.3.3 and wxPython 2.4.2.4u
which works fine. Now, because the GUI is locked during command execution I
have implemented the command execution in a thread and took
http://mail.python.org/pipermail/python-list/2001-May/044903.html as an
example.

Everything works well untill the application crashes without any error
message. I have tried to use the debuger from boa-constructor, but it only
says: application disconnected do you want to stop debugger (something like
this).

Can somebody of you give a an advice how I have to proceed to find the
error. There is only one thread active at one time. The application crashes
at almost the same place. Please imagine this application as one-way script
which works from beginning to the end always the same way showing the result
in a GUI.


Here is the method which starts the thread:

def __execCLI__(self,command=None):
        if not self.worker:
            self.worker = CLIThread(self.parent,command)
            wxLogDebug('CLIThread starting ...')          <- this gets
printed
            self.worker.start()                                        <-- 
start thread
            while self.worker:
                # wait until worker is finished
                wxYield()
            return self.CLIResult


here is the implementation of the thread:

class CLIThread(threading.Thread):
    """Thread to execute CLI commands

    """
    def __init__(self, notify_window, command):
        threading.Thread.__init__(self)
        self._notify_window = notify_window
        self.command = command
        self.ID = None

    def run(self):
        # create result object
        self.result = RESULT()
        # execute command
        try:
            (self.stdin,self.stdout) = os.popen2(self.command)
        except:
            pass
        try:
            # get stdout and write to task output (TO)
            self.line = self.stdout.readline()
            while self.line:
                self.result.addTO(self.line)
                self.line = self.stdout.readline()
            # close self.stdin and self.stdout and set RC
            self.stdin.close()
            self.RC = self.stdout.close()
            if self.RC == None:
                self.result.setRC(0)
            else:
                self.result.setRC(self.RC)
        except:
            pass
        wxPostEvent(self._notify_window,ResultEvent(self.result))






More information about the Python-list mailing list