From 575f102bc2ad6477dbe339043520cdc2ae5d4df7 Mon Sep 17 00:00:00 2001 From: Marc Shervin Ignacio <63439182+Auxes1s@users.noreply.github.com> Date: Wed, 13 May 2026 15:43:24 +0800 Subject: [PATCH] Handle parallel cores and Windows cluster cleanup In bootstrap(), ensure the `cores` argument is set to NULL when parallel flag `pl` is not TRUE, and on Windows create a parallel cluster object when `cores` is a single numeric > 1. Also register an on.exit() to stop the cluster, preventing orphaned worker processes. These changes make pblapply() receive an appropriate `cl` and ensure proper cleanup on Windows when using multiple cores. --- R/bootstrap.R | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/R/bootstrap.R b/R/bootstrap.R index e4a53ae..1f35582 100644 --- a/R/bootstrap.R +++ b/R/bootstrap.R @@ -90,6 +90,17 @@ bootstrap <- function(qteparams, qteest, func) { eachIter <- list() + if (!isTRUE(pl)) { + cores <- NULL + } else if (.Platform$OS.type == "windows" && + is.numeric(cores) && + length(cores) == 1L && + !is.na(cores) && + cores > 1) { + cores <- parallel::makeCluster(as.integer(cores)) + on.exit(parallel::stopCluster(cores), add=TRUE) + } + eachIter <- pblapply(1:iters, bootiter, qteparams=qteparams, func=func, cl=cores) ## if (pl) {