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
}

Try the GALLO package in your browser

Any scripts or data that you put into this service are public.

GALLO documentation built on Nov. 10, 2021, 1:07 a.m.