Should I use threads here?
Steve Holden
sholden at holdenweb.com
Wed Nov 28 11:51:25 EST 2001
"Era Akost" <era_akost at yahoo.de> wrote in message
news:mailman.1006961202.10002.python-list at python.org...
> Hi all,
>
> My problem is the following. I have a program (no
> source code) that takes some data from a file and
> calculates some models. While executing, the program
> outputs continually on the console.
> Now, I want to call this program within a Tkinter GUI.
>
> I call the program (thanks to Steve Holden for the
> answer) through popen2()
>
> i, o = os.popen2('myProgram files')
> for line in o.readlines():
> text.insert(END, line)
> #text is a widget defined somewhere before.
>
> But since I want to write the output on a GUI widget,
> I saw that this happens only after my program is
> executed (I've should have known that). But sometimes
> the programs runs for minutes, so in the meantime I
> want some results beeing displayed in my GUI. Is that
> something can be done with threads? If yes, how? I've
> never used them before. Could someone give me an
> example? (Python 2.01, Win NT)
>
Era:
readlines() doesn't terminate until it knows (by seeing and end of file on
its input stream) that it has read all the input. If you built a loop using
readline() you might find you got better results. This will process your
lines one at a time:
while 1:
line = o.readline()
if not line:
break
text.insert(END, line)
regards
Steve
--
http://www.holdenweb.com/
More information about the Python-list
mailing list