Thursday, 15 January 2015

A way to intervene "after" in tcl -



A way to intervene "after" in tcl -

i have written tcl script there wait 20 seconds in between. have come out of waiting (or rather stop ) in between. have used: after 20000

is there way stop waiting?

in 1 of previous projects @ work, had deal similar situation scripts wait n seconds, go on on, unless user nail ctrl+c, wait canceled. below script, reduced bare essential show how works.

package require tclx proc aborttest {} { after cancel $::afterid set ::status "ctrl+c detected" } # # main # puts "start" set status "ctrl+c not detected" # when ctrl+c detected, phone call aborttest signal trap sigint aborttest # wait n seconds set wait_time 10000 set afterid [after $wait_time {set status "exit normally"}] puts "wait [expr {$wait_time / 1000}] seconds" vwait status; # wait until status changed puts $status puts "end" discussion the signal command said, "if user nail ctrl+c, phone call aborttest" notice in form, after command exit right away, tcl interpreter execute set status ... command 10 seconds later. the vwait command waits until variable status alter value. after 10 seconds, if user had not nail ctrl+c, variable status set "exit normally", @ time, vwait command exits if user nail ctrl+c during time, status changed , vwait command exits update

while reducing original script, took out part cancel after command. putting in. notice after command returns id, used in aborttest cancel action.

tcl

No comments:

Post a Comment