Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Interp limit functionality with vwait call

Closed / Fixed1085023fffffffffffffffffffffffffffffffffCreated 22 years agoUpdated 22 years ago
Descriptionplain2004-12-14 10:09:00
It seems that vwait will not break when timeout 
limit is hit. The following script does not stop:

set testvar ""
interp limit {} time -seconds 5
vwait testvar
nobodyplain2004-12-14 17:47:38
Logged In: NO 

Small addition - first time this problem appeared when I 
tryed to break script execution from C code by setting 
further execution time to one second - result was the 
same.
P.S. Probably it would be handy to have 
"Tcl_SetLimitExceeded" to break executing script

[email protected]
dgp Ticket [1085023fff]: 2 changes [History diff]2004-12-14 23:22:56
dkfplain2004-12-15 01:58:26
Logged In: YES 
user_id=79902

Yeah, I've known about this issue for a while. Not sure how
to fix it yet though.
dkfplain2004-12-16 00:53:49
Logged In: YES 
user_id=79902

Examining what I've done so far, setting up a no-action
timer with Tcl_CreateTimerHandler will be sufficient; that
can be done at the same time as the creation of the time limit.
nobodyplain2004-12-16 18:31:14
Logged In: NO 

This doesn't seems to work, TimerHandler call doesn't 
seems to activate timeout check even with time 
granularity 1.  Possible further problems - there are cases 
when timeout limit check is called too rarely, so it can be 
handy to force such a check each second. Imho, this can 
be done by changing waiting loops (Tcl_Sleep and 
Tcl_DoEvent) to do a limited wait, calling Tcl_CheckLimits 
from time to time without checking time granularity.

Also I've found a small bug with time limits. 
Tcl_SetTimeLimit sets relative timeout while 
Tcl_CheckLimits check absolute timeout. Changes in 
Tcl_SetTimeLimit like
    Tcl_GetTime(&now);
    usec = iPtr->limit.time.usec + now.usec;
    iPtr->limit.time.sec += now.sec + usec / 1000000;
    iPtr->limit.time.usec = usec % 1000000;
    iPtr->limit.exceeded &= ~TCL_LIMIT_COMMANDS;
works, but when You call 
    puts "Limit is: [ interp limit {} time ]"
from script You'll get absolute timeouts, what can be 
misguiding.

[email protected]
dkfplain2004-12-16 23:35:56
Logged In: YES 
user_id=79902

There was a minor error (wrong comparison operator!) in the
time limit evaluation code that made it postpone enforcing
the limit until the end of the second. :^}

Fixing blocking [after] is unpleasant, but fairly
straight-forward.

Fixing blocking [exec] (or other blocking IO) is beyond what
I understand how to do at the moment. :^(
dkfplain2004-12-17 02:39:31
Logged In: YES 
user_id=79902

Fixed [vwait], [update] and [after <num>] to be time-limit
aware.

The fix for [vwait] and [update] is elegant (a timer event
that checks the limit at the time when the limit is expected
to be exceeded) and the fix for blocking [after] is not
(fragment the blocking wait!) but all cases should now work.

Thanks for reporting this!
Log in (anonymous is fine) to add a comment.