[pygtk] Non-blocking subprocess.Popen stop GUI
Bou Baris
boubaris at gmail.com
Mon Aug 31 01:08:09 WST 2009
> Instead of using select() use gobject.io_add_watch() on proc.stdout to
> register a callback function that is used to read the % and set the progress
> bar.
I've modified my code to test gobject.io_add_watch()
I expect that test_io_watch() print in console line readed from proc.stdout
But i see nothing: look like a blocking behaviour (as when use Popen
without use select)
If I stop program with CTRL-C, now I see the output to console/terminal
def test_io_watch(self, file, condition):
print str(file.readline())
return True
def mkv_dts_extraction(self,dtstrack,pgbar=None):
command=['mkvextract', \
'tracks', \
self.INPUTFILE, \
dtstrack + ':' + self.TEMP_DTSFILENAME]
proc=subprocess.Popen(command,stdout=subprocess.PIPE)
outfile=proc.stdout
outfd=outfile.fileno()
file_flags = fcntl.fcntl(outfd, fcntl.F_GETFL)
fcntl.fcntl(outfd, fcntl.F_SETFL, file_flags | os.O_NDELAY)
gobject.io_add_watch(proc.stdout,gobject.IO_IN |
gobject.IO_HUP,self.test_io_watch)
err = proc.wait()
return True
More information about the pygtk
mailing list