[Rd] SUGGESTION: Settings to disable forked processing in R, e.g. parallel::mclapply()

Iñaki Ucar |uc@r @end|ng |rom |edor@project@org
Sun Jan 12 16:03:06 CET 2020

On Sun, 12 Jan 2020 at 00:49, Henrik Bengtsson
<henrik.bengtsson using gmail.com> wrote:
> [snip]
> A final plead: Adding an option to disable forking, at least in the
> 'parallel' package only, will spare people (end users, developers,
> sysadms, ...) many many hours of troubleshooting and eventually trying
> to find workarounds. Those hours adds up quickly given the number of R
> users we have out there.  We have more important things to spend our
> time on.  I can easily count days wasted due to troubleshooting and
> helping others remotely on problems related to instability of forked
> processing. Being able to disable it, would have shortcut this quite a
> bit.

+1 to such an option. I don't see how this could be implemented in
another package. One could do something like

stop_on_fork <- inline::cfunction(
  body='pthread_atfork(stop, NULL, NULL);',
  includes='#include <pthread.h>', convention=".C",
  otherdefs='void stop() { Rf_error("Fork disabled"); }')
parallel::mclapply(1:2, force)

which works nice in a standalone R session, but freezes RStudio.
Another workaround would be

unlockBinding("mclapply", getNamespace("parallel"))
assignInNamespace("mclapply", function(...) stop("Fork disabled"), "parallel")
parallel::mclapply(1:2, force)

(plus several more bindings to cover all the cases), but that's not
allowed, and shouldn't be allowed, on CRAN.


More information about the R-devel mailing list