[pygtk] Non-blocking subprocess.Popen stop GUI
John Finlay
finlay at moeraki.com
Tue Sep 1 03:35:51 WST 2009
Bou Baris wrote:
>> 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
>
I was surprised at your result so I looked back at this message and
realized that the reason it didn't work is because you are waiting for
the process to complete before returning from the mkv_dts_extraction()
method. The above code should work if you remove the line:
err = proc.wait()
John
More information about the pygtk
mailing list