timelimit
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

- endloop -- is used at the end of a loop.
- for -- is used at the beginning of a loop that loops a fixed number of times.
- info("timelimitremaining") -- returns the amount of time available (in seconds) before a loop will time out.
- loop -- is used at the beginning of a loop.
- looparray -- is used at the beginning of a loop that loops over the elements of an array.
- loopdataarray -- is used at the beginning of a loop that loops over the elements of a data array.
- loopindex -- allows a procedure to determine how many times a loop has been repeated.
- loopwhile -- is used at the beginning of a loop.
- Preventing Endless Loops -- setting up a timeout limit to prevent endless loops.
- repeatloopif -- decides whether to continue with a loop or to start over again from the top.
- stoploopif -- decides whether to continue with a loop or to exit the loop immediately.
- until -- is used at the end of a loop, and can control how many times the loop is executed.
- while -- is used at the end of a loop, and can control how many times the loop is executed.

History

Version | Status | Notes
10.2 | New | New in this version.