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
- outputFileList -- list of output files that need to be "completed" before the supplied script is executed. The ::pwtk::job_done command is used to determine if a given output file is completed.
- script -- script to execute
- check_interval_sec -- (optional) time interval (in seconds) for checking if jobs are completed (default = 30 seconds)
- max_waiting_time -- (optional) max waiting time; if jobs are not completed within this time, the command aborts (default = 1 week)
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." } } }