On Linux you can fork a process and then collect it later, as illustrated on the help page ?parallel::mccollect()
; this is more of a hack than a robust feature like future.
> p <- mcparallel({ Sys.sleep(5); "done" })
> sqrt(1:5)
[1] 1.000000 1.414214 1.732051 2.000000 2.236068
> mccollect(p)
$`15666`
[1] "done"
One can implement a similar strategy with snow::sendCall()
/ snow::recvResult()
; see the implementation of snow::clusterCall()
and note that a cluster can be subset, e.g., cl[1]
to set a single node to work. (identically named functions are available in the parallel package, but not exported).
To check whether a job has finished, use wait = FALSE
. Example:
require(parallel)
p1 = mcparallel({Sys.sleep(90); list(tag = "job1", res = 1})
p2 = mcparallel({Sys.sleep(80); 2})
p3 = mcparallel({Sys.sleep(60); 3})
res = mccollect(list(p1, p2, p3), wait = FALSE)
is.null(res)
If none of these 3 jobs has been finished, then res
is NULL.