futureverse / futureverse/future
DOCUMENT: Mention what happens when quitting R while futures are active
- Dominant language
- R
- Stars
- 1k
- Forks
- 92
- PR merge metrics
- No merged PRs in 30d
Description
What happens with active futures that still run in the background when the main R session terminates depends on the backend.
For instance, when using multicore futures, the futures run in child processes of the main R process - terminating the main R process will immediately terminate the child processes when using `quit("no")`. However, when using multisession futures, the futures run in separate processes that will not be terminated when the main R process terminates. Such futures will keep running until resolved. At that stage, the R background session (i.e. `Rscript ... parallel:::.slaveRSOCK()`) will fail to communicate with the main R process and exit with an error.
```r
library("future")
strategy <- "multicore"
plan(strategy)
file <- sprintf("%s.out", strategy)
cat(strategy, " future:\n", file = file)
x %<-% {
for (i in 1:30) {
cat(i, "\n", file = file, append = TRUE)
Sys.sleep(1)
}
}
Sys.sleep(5)
quit("no")
```
gives
```sh
$ cat multicore.out
multicore future:
1
2
3
4
5
```
whereas if we switch to using `strategy <- "multisession"`, we get:
```sh
$ cat multisession.out
multisession future:
1
2
3
...
30
```
Triggered by https://stackoverflow.com/questions/44680172/running-a-r-function-in-background/44714363
Contributor guide
Assessment
This issue has not been assessed yet.