I am working with a function that starts with parallel::makeCluster() and ends with parallel::stopCluster(). Sometimes it crashes in the middle and does not stop the cluster.
Demonstration code:
library('doParallel')
show_problem <- function(n.cores=7) {
clust <- makeCluster(n.cores,type='FORK')
registerDoParallel(cl = clust)
stop('Here is an error message, the function will stop before it gets to the next line.')
parallel::stopCluster(cl = clust)
}
show_problem()
showConnections(all=T)
After the function crashes, showConnections(all=T) will show its “sockconn” connections for workers are still open, and the threads for the workers will still be running. But I can’t call stopCluster() because the object “clust” only exists within the scope of the show_problem() function and that function has ended.
Is there some way for me to find whatever entity “clust” was referring to from outside the function, so I can still run stopCluster() ?