timelimit
LIMIT

The timelimit statement specifies the maximum time a procedure can continue to run after this statement.


Parameters

This statement has one parameter:

limit – is the number of seconds that the procedure can continue to run.


Description

The timelimit statement specifies the maximum amount of time (in seconds) a procedure can continue to run after this statement. If the procedure runs longer than that, it will stop with a timeout error. Here is an example. If it takes more than 10 seconds to run the loop, a message will display the number of iterations that did occur.

timelimit 10
try
    for i,1,10000
        ...
        ...
        ...
    endloop
catch
    message "Loop ran for more than ten seconds, could only finish "+i+" times."
endcatch

The purpose of the timelimit statement is to catch infinite loops, so the limit only affects loops. The time limit is checked each time the loop runs. If there is no loop, the time limit doesn’t apply. For example, consider this program with two sort operations.

timelimit 10
field "Last" sortup
field "First" sortupwithin

If the database contains a million records, the sortup statement will probably take more than ten seconds to run. Nevertheless, the time limit will not kick in, and the program will continue and run to the end, even if it takes minutes.

If you don’t want any time limit, use a timeout value of zero. In this example the loop will always run to ten thousand, no matter how long it takes.

timelimit 0
try
    for i,1,10000
        ...
        ...
        ...
    endloop
catch
    message "Loop ran for more than ten seconds, could only finish "+i+" times."
endcatch

To learn more about this topic, including how to set a general default timeout for all procedures, see Preventing Endless Loops.


See Also


History

VersionStatusNotes
10.2NewNew in this version.