Python, Tkinter and popen problem

norseman norseman at hughes.net
Wed May 27 14:29:52 EDT 2009


This was sent 5/19/09 and as yet has received no comments.
I'm resending just in case a new reader might have an answer.
==================================



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. (Actual syntax was adjusted per 
documentation in each effort.)


The print statements are:
print "Notice of action"
print VariableHavingTextOfAction

print "Closing down\n"

Yes I tried adding the '\n' to the others - no change.

Same loop reads/prints FROM the child's stdout for all three prints.

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. Yes? That is NOT happening. Only closing notice 
appears.  With master having a print ":",returnVal to verify where the 
text screen notices come from - the final print FROM the child is 
verified as captured and printed from the master.

The child has a pause expecting a keystroke from the master immediately
following the print VariableH...   which apparently is never received. 
It is at this point the child hangs.


Again, it's a Python program running a Python program that uses Tkinter.


So what is going on and what can I do to get things running correctly?
I want the master to echo the child's print statements and the child get
the 'continue' character so it will.

Today is: 20090527
Versions noted above.

Steve



More information about the Python-list mailing list