Reputation: 1482
Is there any mechanism in TCL by which i can check TCL Script for going in infinite loop?
For example, I have Test.tcl from which i want to check my a.tcl goes into infinite loop or not? If my a.tcl goes into infinite loop, is it possible to call certain function that "your a.tcl goes infinite loop."
Kind of timers function in c.
Hope that i am clear.
Thanks
Upvotes: 0
Views: 284
Reputation: 7237
Have a look at the interp limit
functions which allows something similar.
Detecting an infinite loop is kind of like the halting problem
so, you can only set a timeout you wish to wait, but not really detect if there really is an infinite loop in the general case.
In some special cases, Tcl warns you if you try to create an infinite loop, especially when trying to start an event loop (via vwait forever
) when there is no event source registered.
For interp limit
see the documentation at:
http://www.tcl.tk/man/tcl/TclCmd/interp.htm#M22
It has an example for terminating an infinite loop in a subinterpreter after a certain amount of commands executed.
set i [interp create]
interp limit $i command -value 1000
interp eval $i {
set x 0
while {1} {
puts "Counting up... [incr x]"
}
}
You can also limit the time allowed for execution.
set i [interp create]
# set a limit to now + 1 seconds
interp limit $i time -seconds [expr {[clock seconds] + 1}]
interp eval $i {
set x 0
while {1} {
puts "Counting up... [incr x]"
}
}
Upvotes: 2