R/autoStopCluster.R

Defines functions autoStopCluster

Documented in autoStopCluster

#' Sub-function to auto-stop the clusters created for parallel processes
#' @param cl The cluster created by the makePSOCKcluster function
#' @importFrom utils capture.output
#' @keywords internal
autoStopCluster <- function(cl) {
  stopifnot(inherits(cl, "cluster"))
  env <- new.env()
  env$cluster <- cl
  attr(cl, "gcMe") <- env
  reg.finalizer(env, function(e) {
    try(parallel::stopCluster(e$cluster), silent = TRUE)
  })
  cl
}
pablobio/GALLO documentation built on March 11, 2021, 2:59 p.m.