Python, Tkinter and popen problem
norseman at hughes.net
Tue May 19 13:43:45 EDT 2009
I have come across a problem that, as I understand all documentation I
have found, should not exist.
Python version is 2.5.2, Tinker in that package.
Linux Slackware 10.2
I went to test os.popen and got mixed answers.
1) IF os.popen opens a command line or command window type
THEN the read and writes work as expected
2) IF os.popen opens a Tkinter contained python program
THEN the read is not consistant and write to it fails.
OK - #1 runs as expected on shell scripts and other programs that were
written for the keyboard and redirectors only. (non GUI types)
#2 popen sometimes connects to stdout OF the child and sometimes
not and has never shown signs of connection to stdin OF child
The Tkinter usage has three (3) print statements. Two (2) never show up.
One does. The one that does is the exit notice.
In the 'child' program; print, sys.stdout.write(string), and
os.write(stdout,string) all work for the one that does write back, but
none work for the two that do not. Don't get picky on the syntax, the
purpose is to get the message across.
The print statements are:
print "Notice of action"
print "Closing down\n"
Yes I added the '\n' to the others - no change.
Same loop reads/prints the stdout FROM child in all three cases.
All three work fine when Tkinter included program is run 'solo'.
Print statements show up in the text (command, whatever) window.
The entire Tkinter included program runs normally except for the I/O
linkage problem when using os.popen(..... or Popen2.popen2 or ... then
only third print shows up in text window. Acts as if first two prints
were captured but never forwarded to screen. If it was a case of not
sending until a system flush() took place then all three lines would
appear at the closing. That is NOT happening. Only closing notice appears.
The child has a pause expecting a keystroke from the master immediately
following the print VariableH... which apparently is never received.
This is a case of Python running a Python program that contains Tkinter.
So what is going on and what can I do?
I want the master to echo the slave's print statements and the slave get
the 'continue' character so it will.
Today is: 20090519
Versions noted above.
More information about the Python-list