Node:Timeout, Next:Pred Summary, Previous:Runtime Utilities, Up:Top
The timeout
package, which may be loaded by the query
| ?- use_module(library(timeout)).
contains the predicate:
time_out(:Goal, +Time, ?Result)
The Goal is executed as if by call/1
. If computing
any solution takes more than Time milliseconds, the goal will fail
and Result is unified with the atom
time_out
. If the goal succeeds within the specified time
Result is unified with the atom success
. Time must
be a number between (not including) 0 and 2147483647.
The time is measured in process virtual time on UNIX. On Windows the time is currently measured in real time (wall time) but you should not rely on this as it may change in the future to use process time on Windows as well.
The precision of the time out interval is usually not better than several tens of milliseconds. This is due to limitations in the timing mechanisms used to implement library(timeout).
time_out/3
is implemented by raising and handling
time_out
exceptions, so any exception handler in the scope of
Goal must be prepared to pass on time_out
exceptions.
The following incorrect example shows what can happen otherwise:
| ?- time_out(on_exception(Q,(repeat,false),true), 1000, Res). Q = time_out, Res = success