Redirect stdout with createfilehandler

Chris Liechti cliechti at gmx.net
Fri Jun 28 18:57:35 EDT 2002


Fabien HENON <fabien.henon at caramail.com> wrote in 
news:3D1CE1FB.9060007 at caramail.com:
 
> With the script below I keep getting the error ' maximum recursion depth 
> exceeded'.
...
> 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())

don't know muchabout tkinter... but here your CALLING stdout_handler, 
you're sure you want this? from the 'root.after' i would expect that you 
should pass a callable as second parameter -> leave away the paranthereses.

  root.after(1000,stdout_handler)

> root.tk.createfilehandler(c_out, Tkinter.READABLE, stdout_handler)
here you pass a callable (a function object here), like i would expect it 
in the other cases too.

> root.after(1000,stdout_handler())
 same here                      ^^

> root.mainloop()
> 8<--------------snap--------------->8

chris

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list