Changeset 57

Show
Ignore:
Timestamp:
24.11.2006 17:03:27 (2 years ago)
Author:
jorge
Message:

handled save_execute error/timeout correctly

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/devel/FuzzyOcr.pm

    r55 r57  
    5151 
    5252    my $end; 
    53     my @time; 
    54     $time[0] = [gettimeofday]; 
     53    my $begin = [gettimeofday]; 
    5554    if ($conf->{focr_global_timeout}) { 
    5655        my $t = get_timeout(); 
     
    7574        $end = fuzzyocr_do( $conf, $pms ); 
    7675    } 
    77     $time[1] = [gettimeofday]; 
    78     debuglog("Processed in ".tv_interval(@time)." sec."); 
     76    debuglog("Processed in ". 
     77        sprintf("%.6f",tv_interval($begin, [gettimeofday])) 
     78        ." sec."); 
    7979    return $end; 
    8080} 
     
    313313                ">>$imgdir/giftext.err", 1); 
    314314 
    315             if ($retcode) { 
     315            if ($retcode<0) { # only care if we timed out 
    316316                chomp $retcode; 
    317317                debuglog("$conf->{focr_bin_giftext} Timed out [$retcode], skipping..."); 
     
    338338                $retcode = save_execute("$conf->{focr_bin_giffix} $file", ">$tfile", ">>$efile"); 
    339339 
    340                 if ($retcode) { 
     340                if ($retcode<0) { # only care if we timed out 
    341341                    chomp $retcode; 
    342342                    debuglog("$conf->{focr_bin_giffix}: Timed out [$retcode], skipping..."); 
     
    388388                $retcode = save_execute("$conf->{focr_bin_gifinter} $cfile", ">$tfile", ">>$efile"); 
    389389 
    390                 if ($retcode) { 
     390                if ($retcode<0) { 
    391391                    chomp $retcode; 
    392392                    printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 
    393393                    debuglog("$conf->{focr_bin_gifinter}: Timed out [$retcode], skipping..."); 
    394394                    ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
     395                } elsif ($retcode>0) { 
     396                    chomp $retcode; 
     397                    printf RAWERR "?? [$retcode] returned from $conf->{focr_bin_gifinter}\n" if ($haserr>0); 
     398                    debuglog("$conf->{focr_bin_gifinter}: Returned [$retcode], skipping..."); 
     399                    ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
    395400                } 
    396401            } 
     
    399404            $retcode = save_execute("$conf->{focr_bin_giftopnm} $tfile", ">$pfile", ">>$efile"); 
    400405 
    401             if ($retcode) { 
     406            if ($retcode<0) { 
    402407                chomp $retcode; 
    403408                printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 
    404409                debuglog("$conf->{focr_bin_giftopnm}: Timed out [$retcode], skipping..."); 
     410                ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
     411            } elsif ($retcode>0) { 
     412                chomp $retcode; 
     413                printf RAWERR "?? [$retcode] returned from $conf->{focr_bin_giftopnm}\n" if ($haserr>0); 
     414                debuglog("$conf->{focr_bin_giftopnm}: Returned [$retcode], skipping..."); 
    405415                ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
    406416            } 
     
    429439            my $retcode = save_execute("$conf->{focr_bin_jpegtopnm} $file", ">$pfile", ">>$efile"); 
    430440 
    431             if ($retcode) { 
     441            if ($retcode<0) { 
    432442                chomp $retcode; 
    433443                printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 
    434444                debuglog("$conf->{focr_bin_jpegtopnm}: Timed out [$retcode], skipping..."); 
     445                ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
     446            } elsif ($retcode>0) { 
     447                chomp $retcode; 
     448                printf RAWERR "?? [$retcode] returned from $conf->{focr_bin_jpegtopnm}\n" if ($haserr>0); 
     449                debuglog("$conf->{focr_bin_jpegtopnm}: Returned [$retcode], skipping..."); 
    435450                ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
    436451            } 
     
    459474            my $retcode = save_execute("$conf->{focr_bin_pngtopnm} $file", ">$pfile", ">>$efile"); 
    460475 
    461             if ($retcode) { 
     476            if ($retcode<0) { 
    462477                chomp $retcode; 
    463478                printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 
    464479                debuglog("$conf->{focr_bin_pngtopnm}: Timed out [$retcode], skipping..."); 
     480                ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
     481            } elsif ($retcode>0) { 
     482                chomp $retcode; 
     483                printf RAWERR "?? [$retcode] returned from $conf->{focr_bin_pngtopnm}\n" if ($haserr>0); 
     484                debuglog("$conf->{focr_bin_pngtopnm}: Returned [$retcode], skipping..."); 
    465485                ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
    466486            } 
     
    488508 
    489509            my $retcode = save_execute("$conf->{focr_bin_bmptopnm} $file", ">$pfile", ">>$efile"); 
    490             if ($retcode) { 
     510            if ($retcode<0) { 
    491511                chomp $retcode; 
    492512                printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 
    493513                debuglog("$conf->{focr_bin_bmptopnm}: Timed out [$retcode], skipping..."); 
     514                ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
     515            } elsif ($retcode>0) { 
     516                chomp $retcode; 
     517                printf RAWERR "?? [$retcode] returned from $conf->{focr_bin_bmptopnm}\n" if ($haserr>0); 
     518                debuglog("$conf->{focr_bin_bmptopnm}: Returned [$retcode], skipping..."); 
    494519                ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
    495520            } 
     
    518543            my $retcode = save_execute("$conf->{focr_bin_tifftopnm} $file", ">$pfile", ">>$efile"); 
    519544 
    520             if ($retcode) { 
     545            if ($retcode<0) { 
    521546                chomp $retcode; 
    522547                printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 
    523548                debuglog("$conf->{focr_bin_tifftopnm}: Timed out [$retcode], skipping..."); 
     549                ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
     550            } elsif ($retcode>0) { 
     551                chomp $retcode; 
     552                printf RAWERR "?? [$retcode] returned from $conf->{focr_bin_tifftopnm}\n" if ($haserr>0); 
     553                debuglog("$conf->{focr_bin_tifftopnm}: Returned [$retcode], skipping..."); 
    524554                ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
    525555            } 
     
    576606 
    577607            my ($retcode, @ocrdata) = save_execute("$scan", ">$imgdir/ocr.temp", ">>$efile",1); 
    578             if ($retcode) { 
     608            if ($retcode<0) { 
     609                debuglog("Timeout: \"$scanset\" took more than $conf->{focr_timeout} sec."); 
     610                debuglog("Skipping scanset due to timeout, trying next..."); 
     611                printf RAWERR qq(Timeout[$conf->{focr_timeout}]: $scanset\n) if ($haserr>0); 
     612                next; 
     613            } elsif ($retcode>0) { 
    579614                chomp $retcode; 
    580615                open ERR,$efile; 
     
    582617                close ERR; 
    583618                my $errstr = join( '', $retcode,@stderr ); 
     619                debuglog("Errors in \"$scanset\""); 
    584620                debuglog($errstr); 
     621                debuglog("Skipping scanset because of errors, trying next..."); 
    585622                printf RAWERR qq($errstr\n) if ($haserr>0); 
    586                 debuglog("Skipping scanset \"$scanset\" because of errors, trying next..."); 
    587623                next; 
    588624            } 
  • trunk/devel/FuzzyOcr/Deanimate.pm

    r55 r57  
    3737            ">$tfile3", 
    3838            ">>$efile"); 
    39         if ($retcode) { 
    40             debuglog("$conf->{'focr_bin_gifsicle'}: Timed out [$retcode], image not reduced!")
     39        if ($retcode == 0) { 
     40            $tfile = $tfile3
    4141        } else { 
    42             $tfile = $tfile3; 
     42            debuglog("$conf->{'focr_bin_gifsicle'}: ". 
     43                ($retcode<0) ? 'Timed out' : 'Error' 
     44                ." [$retcode], image not reduced!"); 
    4345        } 
    4446    } 
     
    4749        ">$tfile2", 
    4850        ">>$efile"); 
    49     if ($retcode) { 
    50         debuglog("$conf->{focr_bin_gifsicle}: cannot extract image#${index}"); 
    51         return $tfile; 
    52     } 
    53     return $tfile2; 
     51    return $tfile2 if ($retcode == 0); 
     52    debuglog("$conf->{focr_bin_gifsicle}: cannot extract image#${index}"); 
     53    return $tfile; 
    5454} 
    5555 
     
    7979 
    8080    if ($retcode) { 
    81         debuglog("$conf->{'focr_bin_gifsicle'}: Timed out [$retcode], data unavailable..."); 
     81        debuglog("$conf->{'focr_bin_gifsicle'}: ". 
     82            ($retcode<0) ? 'Timed out' : 'Error' 
     83            ." [$retcode], data unavailable..."); 
    8284        return \%info; 
    8385    } 
  • trunk/devel/FuzzyOcr/Hashing.pm

    r55 r57  
    339339    if ($r) { 
    340340        chomp $r; 
    341         debuglog("$conf->{focr_bin_ppmhist}: Timed out [$r], skipping..."); 
     341        debuglog("$conf->{focr_bin_ppmhist}: ". 
     342            ($r<0) ? 'Timed out' : 'Error' 
     343            ." [$r], skipping..."); 
    342344        return (1, ''); 
    343345    } 
  • trunk/devel/FuzzyOcr/Misc.pm

    r55 r57  
    77use lib "../"; 
    88use FuzzyOcr::Config qw(set_pid unset_pid get_timeout get_pms get_config set_config debuglog logfile);; 
     9use Time::HiRes qw( time usleep ualarm gettimeofday tv_interval ); 
    910 
    1011# Provide some misc helper functions 
     
    4445    $stdout = '>/dev/null' unless $stdout; 
    4546    $stderr = '>/dev/null' unless $stderr; 
    46     debuglog("Exec: $cmd $stdout $stderr"); 
    4747    my $retcode; 
    4848    if ($conf->{'focr_global_timeout'}) { 
     
    5858        } else { 
    5959            set_pid($pid); 
    60             wait(); $retcode = $?>>8; 
     60            wait(); 
     61            $retcode = $?; 
    6162            unset_pid(); 
    6263            if ($return_stdout and $stdout !~ m,/dev/null,i) { 
     
    7374        my $pid; 
    7475        $t->run_and_catch(sub { 
     76            my $begin = [gettimeofday]; 
    7577            $pid = fork(); 
    7678            if (not defined $pid) { 
     
    7880                return -1; 
    7981            } elsif (not $pid) { 
     82                debuglog("Exec: $cmd $stdout $stderr"); 
    8083                open(STDOUT, $stdout); 
    8184                open(STDERR, $stderr); 
     
    8487            } else { 
    8588                set_pid($pid); 
    86                 wait(); $retcode = $?>>8; 
     89                my $wpid = wait(); $retcode = $? >>8; 
     90                debuglog("Elapsed: ". 
     91                    sprintf ("%.6f",tv_interval($begin, [gettimeofday])) 
     92                    ." sec. ($cmd)"); 
    8793                unset_pid(); 
    8894                if ($return_stdout and $stdout !~ m,/dev/null,i) {