MacroPackage: systemToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.1
Unrevised from 10.0 to 10.1.
10.0 version

with-timeout

Arguments: (seconds &body timeout-body) &body body

This macro evaluates the body as a progn body. If the evaluation of body does not complete within the specified interval, execution throws out of the body and the timeout-body forms are evaluated as a progn body, returning the result of the last form. The timeout-body forms are not evaluated if the body completes within seconds.

The value of seconds may be any real number. A negative or zero value causes the timeout-body to be executed immediately. This macro uses operating system utilities for timing so its granularity depends on the granularity of the operating system functions. We cannot in this page specify the granularity you will see (since this page is generic over many systems and environmental factors affect the result) but we can say that seconds of less than about 0.08 will always time out on most Unix systems. We strongly recommend that you test this macro to find out the granularity on your system.

When the debugger takes control on a Lisp thread, it temporarily blocks the triggering of any dynamically-enclosing with-timeout forms. The block goes away when the debugger returns to wherever it's going.

Here is an example of code using sys:with-timeout. We define a variant of y-or-n-p which times out after a specified number of seconds, taking the default value specified in the arguments.

(defun y-or-n-p-with-timeout (seconds default &rest args)
  (sys:with-timeout (seconds (format t "[Timed out] ~a~%" default)
	     default)
	 (apply #'y-or-n-p args)))

See mp:with-virtual-timeout, which is a similar macro but restricts time counting to the timeout to non-gc time actually spent in the process running when the macro was called. Also see multiprocessing.htm for general information on multiprocessing in Allegro CL.


Copyright (c) 1998-2017, Franz Inc. Oakland, CA., USA. All rights reserved.
This page was not revised from the 10.0 page.
Created 2017.2.15.

ToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.1
Unrevised from 10.0 to 10.1.
10.0 version