A batchtools backend that resolves futures sequentially in transient background R sessions
Source:R/batchtools_local.R
batchtools_local.RdThe batchtools local backend is useful for verifying parts of your batchtools setup locally, before using a more advanced backend such as the job-scheduler backends.
Usage
batchtools_local(
...,
fs.latency = 0,
delete = getOption("future.batchtools.delete", "on-success")
)Arguments
- fs.latency
[
numeric(1)]
Expected maximum latency of the file system, in seconds. Set to a positive number for network file systems like NFS which enables more robust (but also more expensive) mechanisms to access files and directories. Usually safe to set to0to disable the heuristic, e.g. if you are working on a local file system.- delete
Controls if and when the batchtools job registry folder is deleted. If
"on-success"(default), it is deleted if the future was resolved successfully and the expression did not produce an error. If"never", then it is never deleted. If"always", then it is always deleted.- ...
Not used.
Details
Batchtools local futures use batchtools cluster functions
created by batchtools::makeClusterFunctionsInteractive() with
external = TRUE.
The batchtools local backend is synchronous, that is, the main R process
blocks while a job is running. This means that nothing can be relayed from
a job until it is done. For example, immediate conditions, such as
progress updates signaled by the progressr package, are relayed
first when the job has finished. To get them as soon as possible, use an
asynchronous backend, e.g. batchtools_multicore() with two or more
workers, or a job scheduler.
An alternative to the batchtools local backend is to use
plan(future::cluster, workers = I(1)).
Examples
library(future)
plan(future.batchtools::batchtools_local)
message("Main process ID: ", Sys.getpid())
#> Main process ID: 2296737
f <- future({
data.frame(
hostname = Sys.info()[["nodename"]],
os = Sys.info()[["sysname"]],
cores = unname(parallelly::availableCores()),
pid = Sys.getpid(),
modules = Sys.getenv("LOADEDMODULES")
)
})
info <- value(f)
print(info)
#> hostname os cores pid
#> 1 hb-x1-2023 Linux 8 2297548
#> modules
#> 1 CBI:cmake/4.3.3:r/4.6.1:pandoc/3.12:quarto/1.10.18:port4me/0.7.1:bat/0.26.1:fzf/0.74.4:glow/2.1.2:github-cli/2.102.0:tea/0.16.0:git-flow/1.12.3:git-extras/7.5.0:difftastic/0.69.0:ripgrep/15.2.0:shellcheck/0.11.0:node/26.0.0:markdownlint-cli/0.49.1:gitleaks/8.30.1:rclone/1.74.4:himalaya/2.2.1:rust/1.97.1:osgrep/0.5.16:opencode/1.15.12:bash-startup/0.5.0:restic/0.19.1:deno/2.9.7