[pygtk] gobject.io_add_watch buffered?

Gabriele Lanaro gabriele.lanaro at gmail.com
Wed May 6 04:51:48 WST 2009


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 a gmail.com>


More information about the pygtk mailing list