TABLE OF CONTENTS


::pwtk::afterDone

SYNOPSIS

proc ::pwtk::afterDone {outputFileList script {check_interval_sec 30} {max_waiting_time week}} {

PURPOSE

Execute a supplied 'script' after the calculations associated with the list of output files specified in 'outputFileList' are all completed.

This command is blocking, it returns only after the execution of 'script' is finished.

ARGUMENTS

SOURCE

    foreach out $outputFileList {
        fileMustExist $out "output"
    }

    print "The following script will be executed after the [join $outputFileList {, }] jobs are completed:\n\n[::pwtk::trimText $script]\n"
    print -nonewline "waiting"

    set check_interval_ms   [time2ms $check_interval_sec]
    set max_waiting_time_ms [time2ms $max_waiting_time]
    set elapsed_ms 0
    
    while 1 {
        puts -nonewline .
        flush stdout
        
        after $check_interval_ms

        set done 1
        set error 0
        foreach out $outputFileList {
            if { [file exists [set errF $out.error]] } { set error 1 }
            if { ! [job_done $out] } { set done 0; break }
        }  
        if { $done } {
            puts ""
            # execute the 'script'
            set code [catch {uplevel 1 $script} result]
            return -code $code $result
            
        } elseif { $error } {
            puts ""
            # an error has occured
            ::pwtk::error "The $errF file exists,
indicating that an error occured.
For details, see:  $outputFile.error" 1 
        }

        set elapsed_ms [expr $elapsed_ms + $check_interval_ms]

        # prevent the loop going on indefinitely
        
        if { $elapsed_ms > $max_waiting_time_ms } {
            ::pwtk::abort "Maximum waiting time of $max_waiting_time_ms ms reached,
but the jobs associated with [join $outputFileList {, }] are not completed."
        }
    }
}