[pygtk] gobject.io_add_watch buffered?
Gabriele Lanaro
gabriele.lanaro at gmail.com
Wed May 6 20:42:29 WST 2009
Now it's ok, with the flush() method the program give me the string every 2 seconds, but I have another problem:
I substitute the print text in the gobject.io_add_watch callback with a thing like this:
----------------- -----------------------------------
class CodeLauncher
def __init__(self,executable,self.args):
# WIDGET DEFINITIONS, there is also the window etc..
tv=gtk.TextView()
self.buffer=tv.get_buffer()
def run(self):
p=subprocess.PIPE
cmdline=self.executable,self.args
child=subprocess.Popen(cmdline,stdout=p)
gobject.io_add_watch(child.stdout,gobject.IO_IN | gobject.IO_HUP,self.writeout,priority=gobject.PRIORITY_HIGH)
gtk.main()
def writeout(self,file,event):
text=1
while text:
text=file.readline()
iter = self.buffer.get_end_iter()
self.buffer.insert(iter,text)
-------------------------------------------------------
Now the problem is that the output of the program is visualized only when the program spawned (ex. blocking.py with flush)returns..and in the middle the interface is blocked.
Maybe I've forgotten something...
--------
On Wed, 6 May 2009 07:22:01 +0200
Andi Albrecht <albrecht.andi a googlemail.com> wrote:
> 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
--
Gabriele Lanaro <gabriele.lanaro a gmail.com>
More information about the pygtk
mailing list