Should I use threads here?

Era Akost era_akost at yahoo.de
Thu Nov 29 04:55:58 EST 2001


> This may be true. But the readline() solution *can't* be any worse, and
> might be better. Readlines() will definitely not return until the called
> program closes its standard output. Of course, if Era has no access to the
> program's source he has no possibility of adjusting its output behavior.
> 
> regards
>  Steve

Hi all,

Steve, I tried your suggestion, but that didn't change the situation.
Let me explain it again. I have a simple GUI with a button
and a text widget. When I click the button, the following fuction is called:

def execute(self, command):
#command is a string containing the .exe program and its file arguments
    i, o = os.popen2(command)
    while 1:
        line = o.readline()
        if not line:
            break
        self.text.insert(END, line)
    i.close(), o.close()

Now, the button on the GUI remaines clicked for a while (it seems to me
all the time that the .exe program is running). And only after that, its
output is displayed in the text widget.

But this is not the way the .exe program behaves when it runs on
its own. During the execution it keeps displaying the results on the console.
And this is exactly the behaviour that I'd like for my GUI.
Thus, I asked if threads can do something in this case. Only that I
don't yet understand how threads work, and so on - therefore I need some help.

Again, many thanks
Era



More information about the Python-list mailing list