| local_timeout | R Documentation |
local_timeout() sets a time limit for the rest of the function that calls
it. The limit applies to each FFmpeg, FFprobe or MediaInfo program that the
function starts after this call. When the function returns, or stops with an
error, the caller's own limit is back, except in the cases in Details.
Use with_timeout() to set a limit on one expression. Use local_timeout()
to set a limit on the rest of a function, or on several calls that are hard
to wrap in one expression.
local_timeout(seconds, .local_envir = parent.frame())
seconds |
A whole number of seconds. |
.local_envir |
The environment that holds the limit. The default is the
function that calls |
The limit applies to each program, not to the whole function. In a 100-row
batch after local_timeout(600), each program that a row starts gets 600
seconds, plus the delay that with_timeout() describes. The workers of a
parallel = TRUE run use the same limit.
R can wait up to 40 seconds past the limit, and with_timeout() explains
why. It also explains what happens when a limit is reached.
Two calls in one function work like any two local_*() calls. The second
limit applies until the function ends. Then both are undone, and the caller's
limit is back.
In three cases, the caller's limit is not back when the function ends, and there is no error.
The function calls on.exit() without add = TRUE. That call removes the
undo step. Write on.exit(..., add = TRUE) instead.
The .local_envir belongs to a function that has returned, or it is an
environment such as new.env().
local_timeout() is called directly inside the expression of
with_timeout(). There, local_timeout() belongs to the function around
it. So when that function ends, the limit that with_timeout() set is in
force. Put the inner limit in a function of its own, or use only one of
the two.
The first two cases also apply to withr::local_options(), because R's exit
handlers work this way. They do not apply to withr::with_options(), which
puts the option back itself.
The caller's earlier setting, invisibly. It is a list with one
element, the same form that withr::local_options() returns.
with_timeout() to set a limit for one expression.
tidymedia-package describes the session options.
bounded <- function() {
local_timeout(30)
getOption("tidymedia.timeout")
}
# In force for the rest of that function...
bounded()
# ...and gone once it has returned.
getOption("tidymedia.timeout", default = "unset")
# Bound every program a whole function starts, at five minutes. Defining the
# function starts nothing; the limit applies when you call it.
convert_all <- function(files) {
local_timeout(300)
for (f in files) extract_audio(f, sub("[.][^.]*$", ".wav", f))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.