[pygtk] gobject.io_add_watch buffered?
Andi Albrecht
albrecht.andi at googlemail.com
Wed May 6 13:22:01 WST 2009
I think it's stdout that's buffered here. Have you tried to flush
stdout after each print to actually write the output?
import sys, time
sys.stdout.write("foo 1")
sys.stdout.flush()
time.sleep(2)
...
Andi
2009/5/5, Gabriele Lanaro <gabriele.lanaro at gmail.com>:
>
> Hi, I'm looking for redirecting the output of a command in a TextWidget and
> I'm using subprocess and gobject.io_add_watch.
> The problem is that sometimes it gives me a buffered output, for example
> with this test program..
> blocking.py----------------
> import time
> print "Passati 0 secondi"
> time.sleep(2)
> print "Passati 2 secondi"
> time.sleep(2)
> print "Passati 4 secondi"
> ----------------------------
> gives me the output all toghether after 4 seconds.
>
> The code fragment of the program interested in spawning the process is that:
> codelauncher.py--------------
> class CodeLauncher:
> --------------
> --------------
> def run(self):
> cmdline="python blocking.py"
> child=subprocess.Popen(cmdline,stdout=subprocess.PIPE)
> gobject.io_add_watch(child.stdout,gobject.IO_IN |
> gobject.IO_HUP,self.writeout)
> def writeout(self,file,event):
> text=1
> while text:
> text=file.readline()
> print text,
> -----------------------
>
> --
> Gabriele Lanaro <gabriele.lanaro at gmail.com>
> _______________________________________________
> pygtk mailing list pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
>
More information about the pygtk
mailing list