inst/testme/test-callr,worker-termination.R

library(future.callr)

message("*** callr() - terminating workers ...")

plan(callr, workers = 2L)

all <- nbrOfWorkers()
free <- nbrOfFreeWorkers()
stopifnot(
  nbrOfWorkers() == 2L,
  nbrOfFreeWorkers() == 2L
)

## Force R worker to quit
f <- future({ tools::pskill(pid = Sys.getpid()) })
res <- tryCatch(value(f), error = identity)
print(res)
stopifnot(inherits(res, "FutureError"))

stopifnot(
  nbrOfWorkers() == all,
  nbrOfFreeWorkers() == free
)

message("*** callr() - terminating workers ... DONE")

Try the future.callr package in your browser

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

future.callr documentation built on June 8, 2025, 1:24 p.m.