From |uc@r @end|ng |rom |edor@project@org  Sun Jan 12 16:03:06 2020
From: |uc@r @end|ng |rom |edor@project@org (=?UTF-8?Q?I=C3=B1aki_Ucar?=)
Date: Sun, 12 Jan 2020 16:03:06 +0100
Subject: [Rd] SUGGESTION: Settings to disable forked processing in R,
 e.g. parallel::mclapply()
In-Reply-To: <CAFDcVCRg7Ygr1F+=fgaHq2NaJsM5RsUTLUsNdC3=6x=agigJ1Q@mail.gmail.com>
References: <84d162f5-dd0d-64e6-e9bf-54b65a10faa6@gmail.com>
 <DCF5422D-5237-48C1-BE51-486CA3C1DD60@r-project.org>
 <CAFDcVCS0RwA0-64FTY6kiOk6=yxy8w4OweVbESa-3G6JHtV6Xg@mail.gmail.com>
 <6D7F010F-60B4-4C51-99B3-D8B51BE7572A@R-project.org>
 <CAFDcVCR-aMss6QNrscaYgVfYANYkznFTxRdqxUVeu51qTFTnDg@mail.gmail.com>
 <EA77CEE0-1018-4667-856D-1F3C98D015BB@R-project.org>
 <CAFDcVCRg7Ygr1F+=fgaHq2NaJsM5RsUTLUsNdC3=6x=agigJ1Q@mail.gmail.com>
Message-ID: <CALEXWq2NvtwHFMhbCV5y4d-aG-M25V7aoD_CKJyfGtYn5jDZ-w@mail.gmail.com>

On Sun, 12 Jan 2020 at 00:49, Henrik Bengtsson
<henrik.bengtsson at 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"); }')
stop_on_fork()
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.

I?aki



[Rd] SUGGESTION: Settings to disable forked processing in R, e.g. parallel::mclapply()
=?UTF-8?Q?I=C3=B1aki_Ucar?=