Redirect stdout with createfilehandler
Fabien HENON
fabien.henon at caramail.com
Fri Jun 28 18:23:55 EDT 2002
I am trying to redirect stdout from a raytracer back to a Tkinter Text
with createfilehandler.
With the script below I keep getting the error ' maximum recursion depth
exceeded'.
I have been stuck with this redirection problem for 2 months. This is
driving really nuts now.
If I turn off the verbose in the command line '-v', the image is
raytraced till the end with the recursion error.
If I turn the verbose on, the raytrace stops after roughly a second.
What the raytracer does when the verbose is turned on, is to spit out
the line being rendered while raytracing.
I get the image, not the stdout to the Tkinter text.
Could one Guru tell me what I am doing wrong here.
Or at least have one working example
One thing :
You can download the executable and the POV script (the raytracer) at
http://pyvon.sourceforge.net/executable_file.tgz
Fabien HENON
8<-------------snip--------------->8
import sys,os
import Tkinter
from Tkinter import *
root = Tk()
T=Text(root)
T.pack()
cmd = 'mega +i1.pov +w320 +h240 +dgt +v -f'
c_in,c_out=os.popen4(cmd)
def stdout_handler():
T.insert('1.0',c_out)
root.tk.deletefilehandler(c_out)
root.tk.createfilehandler(c_out, Tkinter.READABLE, stdout_handler)
root.after(1000,stdout_handler())
root.tk.createfilehandler(c_out, Tkinter.READABLE, stdout_handler)
root.after(1000,stdout_handler())
root.mainloop()
8<--------------snap--------------->8
More information about the Python-list
mailing list