Question about behaviour of foreach and Glib:IO-> add_handler


I was always under the impression that a foreach loop iterated over a
list sequentially, which in every other case at least seems to happen.

However I have the following code

sub encode_loop {
my ($opts,$prog,$ext,$sel_opts_vbox)= _;
my $subname='encode';
        foreach my $files1 (keys %files){
                no strict 'refs';
                        if (${$files{$files1}}[0] eq $subname){
                        my $prog=&run_cmd($files1,$opts,$prog,$ext,$subname,$sel_opts_vbox) ;

Which runs the following sub-routine (abrev) for each file ($files above)

sub run_cmd {
$pid=open($file, "-|","$cmd{$subname} 2>&1") or die "Failed running
perl subprocess\n";

my $end_mark;
my $feedback_type=$options{'feedback'};
        if ($feedback_type eq

our $tag=  Glib::IO->add_watch ( fileno($file), ['in', 'hup'], sub {
my ($fileno, $condition,$tag) = @_;

        if ($condition eq 'hup') {
        close $file;
        return 0;
my $line ;

sysread $file, $line, 256;

        if ($feedback_type eq '0'){

        else {
        $buffer->insert($buffer->get_end_iter, $line);
        return 1;

        if ($feedback_type eq '1'){

However the sub is run for each file in parallel. Anyone have any idea
how to force sequential mode? I suspect that it has something to do
with the buffer/add_watch stuff returning immediately after read.

As this program does video transcoding it would be nice to find a
solution as the times are very long


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]