[pygtk] Asynchronous access at output of os.popen() call

Pádraig Brady P at draigBrady.com
Wed Aug 20 18:04:32 WST 2008


togix wrote:
> Hi,
> I'm working on a GUI in PyGTK that allows to insert some parameters and then to call a program (written in C) using the os.popen() function.
> 
> The thing that I want to do is redirect the standard output of the called program into a gtk.TextView() box [b]in runtime[/b],
> so to show the lines when they come out in a asynchronous way, not all the end of execution.

Yes there are 2 issues here.
The first is that os.popen() doesn't return until the subprocess is finished.
The second is that there is probably buffering happening that is not desirable.

To address the first issue, and read from the subprocess asynchronously
you could try my subprocess module, with a timeout:
http://www.pixelbeat.org/libs/subProcess.py

To understand/control any additional buffering which may happen, see:
http://www.pixelbeat.org/programming/stdio_buffering/

Pádraig.



More information about the pygtk mailing list