An R6 class for a pool of SecureSession objects that are started ahead of time.
The pool starts all its sessions when you create it, so $execute() can
use an idle one straight away instead of waiting for R to start. Each
session goes back to the pool when its run finishes, whether it succeeded
or failed.
Threads and forks
SecureSessionPool isn't thread-safe. Handing out and taking back
sessions uses no locks. If you use pools from several processes (for
example with parallel::mclapply or future), create a pool
in each process. Two processes sharing one pool can end up grabbing the
same session.
Methods
Method new()
Start a new SecureSessionPool
Usage
SecureSessionPool$new(
size = 4L,
tools = list(),
sandbox = TRUE,
limits = NULL,
verbose = FALSE,
reset_between_uses = FALSE
)Arguments
sizeInteger, number of sessions to start (default 4, minimum 1).
toolsA list of
securer_tool()objects passed to each session.sandboxLogical, whether to use the OS sandbox.
limitsOptional named list of resource limits.
verboseLogical, whether to print what each session is doing.
reset_between_usesLogical, whether to restart each session before it goes back to the pool (default
FALSE). WithTRUE, the pool callssession$restart()after every$execute(), so variables, loaded packages, and options from one run don't carry over to the next.
Method execute()
Run R code on an idle session from the pool
Arguments
codeCharacter string of R code to execute.
timeoutTimeout in seconds, or
NULLfor no timeout.acquire_timeoutOptional number of seconds to wait for a free session. If
NULL(the default), the call fails straight away when every session is busy. Otherwise the pool keeps trying, every 0.1 seconds, until the time is up.
Method format()
Format the pool for printing
Method print()
Print method
Method close()
Close every session in the pool