R/with_timeout.R

Defines functions with_timeout

Documented in with_timeout

#' This function will prevent infinite loop
#' We can define the runing time for each file
with_timeout <- function(expr, cpu, elapsed) {
  expr <- substitute(expr)
  envir <- parent.frame()
  setTimeLimit(cpu = cpu,
               elapsed = elapsed,
               transient = TRUE)
  on.exit(setTimeLimit(
    cpu = Inf,
    elapsed = Inf,
    transient = FALSE
  ))
  eval(expr, envir = envir)
}
emse-p4a-gwu/p4aGrader documentation built on May 16, 2020, 1:43 a.m.