Should I use threads here?

Steve Holden sholden at holdenweb.com
Thu Nov 29 13:43:00 CET 2001


"Martin Franklin" <martin.franklin at westgeo.com> wrote ...
> Era Akost wrote:
>
> >> 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
> >
>
>
> Era,
>
> Try calling self.text.update() in the loop.
>
Also, are we to understand that you are doing all this inside the event
callback for a button click? That sounds possible if the button isn't
"popping up" again for a long time. Maybe you *do* need a thread. Report
back about whether the update() calls help...

regards
 Steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list