Closed MalditoBarbudo closed 1 year ago
I don't have much knowledge in this area, but one thing you could try, both to narrow in on the root issue of the crash and as an alternative to "multisession" is to install the package "future.callr" and then use the following plan (instead of the "multisession" plan):
future::plan(future.callr::callr)
If you don't switch back to sequential at the end, do things still work well with the above plan?
@scottkosty
Yes, using future.callr::callr
as plan works as intended. R processes are spammed when computation begins, and closed afterwards, freeing the memory. Also, Rstudio doesn't crash when restarting/closing session without changing plan to sequential.
I can use this workaround for the moment for my own development, but I would like to know why is this happening with plans from future
, as is the default recommendation in docs from furrr
and other packages and probably the one that users of the package I'm developing will use.
Is there any more info I can provide to help narrowing the issue?
(Please use https://github.com/HenrikBengtsson/future/discussions for Q&A)
Describe the bug
When using
future::plan(future::multisession)
in linux, this creates as R workers as especified in the workers arguments that are not closed until the plan is changed back to sequential or the session is closed/reinitialized. The latter in Rstudio almost always results in a crash of the R sessionReproduce example
Simply changing the plan to multisession creates the issue. R session processes can be monitored with
htop
,btm
or the console system monitor of your choice:btm screenshot after changing plan:
As it can seen, R processes appear.
btm screenshot showing that memory is still used in each fork after computation ends:
Restarting the session (building and restarting for package development, changing project...) crash R session causing it to restart and can lead to data loss.
Changing the plan to sequential before exiting the session removes sucessfully the R workers
btm screenshot after changing to sequential:
Expected behavior
When ussing
plan(multisession)
I expect those processes to be terminated after computation finish and results are gathered, or at least that RStudio does not crash if plan is not changed back to sequential before restarting/closing the session.Session information
Created on 2023-06-23 with reprex v2.0.2
Future session info when in sequential
Created on 2023-06-23 with reprex v2.0.2
Future session info when in multiprocess
Created on 2023-06-23 with reprex v2.0.2