futureverse / parallelly

R package: parallelly - Enhancing the 'parallel' Package
https://parallelly.futureverse.org
130 stars 7 forks source link

WISH: cloneNode() - clone a RichSOCKnode #102

Closed HenrikBengtsson closed 1 year ago

HenrikBengtsson commented 1 year ago

Add generic function cloneNode() with implementation for RichSOCKnode, e.g.

library(parallelly)
cl <- makeClusterPSOCK(2L)
node <- cl[[2]]
node
## node of a socket cluster on host 'localhost' with pid 1256882
another_node <- cloneNode(node)
another_node
## node of a socket cluster on host 'localhost' with pid 1256886
cl <- c(cl, another_node)

This would make it possible to restart crashed workers, e.g.

for (kk in seq_along(cl)) {
  node <- cl[[kk]]
  if (!isNodeAlive(node)) {
    node <- cloneNode(node)
    cl[[kk]] <- node
  }
}

For this to work, the RichSOCKnode object needs to record all details on how it was launched.