fromchild.readlines() blocks Tkinter

Fabien Hénon ffjhenon at club-internet.fr
Tue May 21 19:01:09 EDT 2002


I am writing an application (using Tkinter) to start a free raytracer
(POVRAY which executable is x-povray) from the Tkinter GUI (under
Linux).

When started from a terminal, POVRAY reads a script (like Python), and
outputs both an image and the line which is being rendered to the
console.
When the image is completely raytraced, POVRAY displays the stats on the
console.
If there are errors in the read script, the error message is also
displayed on the console.


self.text_out is the window to which the stats and rendered line numbers
are redirected.
the command (cmd) is :
/usr/local/bin/x-povray +i/usr/local/pov/1.pov +w320 +h240 -f +dgt +v

I need to be able to kill (or renice) the child process. That's why I
use the class
popen2.Popen4 and to mix stdout and stderr.

Here is my script to launch the external raytracer (I start with
self.render):


    def render(self):

     RUN=popen2.Popen4(cmd)
      pid=RUN.pid
      sortie=RUN.fromchild.fileno()
      root.after(500,self.pulse)

    def pulse(self):
      if pid != 0:
        Tkinter._tkinter.createfilehandler(RUN.fromchild.fileno(),
         Tkinter._tkinter.READABLE,
         self.test)
      else:
        self.null

    def null(self):
      pass


    def test(self,sortie,mask):

#     """  8<-snip-beginning of comment-->8

      for line in RUN.fromchild.readlines():
        if line.endswith('\n'):
          line=line[:-1]+'\n'
          self.text_out.insert('end',line)
        self.text_out.yview('moveto', 1.0)

#     """  8<-snap-----end of comment---->8

      Tkinter._tkinter.deletefilehandler(RUN.fromchild.fileno())
      root.after(500,self.pulse)



My problem comes from RUN.fromchild.readlines().I also tried
sys.stdout.readlines()
When I comment out the section between the snip and snap above, the GUI
is not blocked ( I can have access to the menu and buttons), but I don't
get
the stats.
When the section between the snap is not commented out(as above), I get
the feedback from
the console, but I cannot stop the raytrace or access the GUI.

Help, what shall I do ?
Sorry for this lengthy post.

Thanks for any help. I have been stuck with this for several weeks.

Fabien




More information about the Python-list mailing list