View source: R/forestsearch_helpers.R
| reset_workers | R Documentation |
Tears down the current future plan, forces garbage collection, optionally pauses, and spins up a fresh worker pool. Used to release worker-side memory between simulation phases (e.g. between alternative and null Monte Carlo runs) so that accumulated R-session state in long-running workers does not bloat memory or cause sporadic failures.
reset_workers(
workers = NULL,
strategy = "multisession",
sleep = 1,
gc = TRUE,
quiet = FALSE
)
workers |
Integer. Number of workers for the new pool.
Default |
strategy |
Character. The future strategy to
reinstate. Default |
sleep |
Numeric. Seconds to pause between teardown and
setup. Default |
gc |
Logical. Whether to force garbage collection between
teardown and setup. Default |
quiet |
Logical. Suppress informational |
The worker reset sequence is:
future::plan("sequential") – dismantles the
existing worker pool; R processes terminate and their memory
is returned to the OS.
gc(verbose = FALSE) – reclaims main-process memory
holding references to now-defunct futures.
Sys.sleep(sleep) – brief pause to let the OS
reclaim sockets / pipes before the new pool is requested.
A small non-zero sleep (the default 1) materially
reduces multisession setup failures observed on busy
Linux servers; set to 0 to skip.
future::plan(strategy, workers = workers) – starts
a fresh pool.
This function is a no-op if future is not installed or if
the requested strategy cannot be initialised; a warning is emitted
and the previous plan is left in place.
Invisibly, a list with the previous and current plan
class names: list(previous = <chr>, current = <chr>).
collect_results for error-tolerant
collection of foreach output.
if (requireNamespace("future", quietly = TRUE)) {
future::plan("multisession", workers = 2L)
# ... run alternative simulations ...
reset_workers(workers = 2L)
# ... run null simulations ...
future::plan("sequential")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.