[R] Auto-killing processes spawned by foreach::doMC
Steve Lianoglou
mailinglist.honeypot at gmail.com
Tue Nov 9 15:03:55 CET 2010
Hi Henrik,
Firstly, thanks for keeping an eye out and sharing.
On Tue, Nov 9, 2010 at 12:59 AM, Henrik Bengtsson <hb at biostat.ucsf.edu> wrote:
> I just stumbled into the 'fork' package (GPL-2). It allows you do
> send signals from within R. Unfortunately it is not available on
> Windows, but it is definitely a start.
This isn't so horrible within the context of my question (which was
using foreach with doMC -- the wrapper for multicore) since multicore
itself doesn't run on windows.
I guess we'd just have to have some "global cache" in the main R
workspace (that drives the processor splitting) that stores PIDs of
the child processes spawned by foreach/doMC, which I guess we could
later send kill() signals to if they were abnormally interrupted ...
will have to look into it later.
Thinking about it, I reckon the multicore package must have something
similar? Will investigate ...
-steve
>
> Here is an example how an R session can send an interrupt signal
> (SIGINT) to itself:
>
> library("fork");
>
> # Get the process ID of the current R session
> pid <- getpid();
>
> # Run some code and interrupt the current R session
> tryCatch({
> print("Tic");
> Sys.sleep(2);
> print("Tac");
> kill(pid, signal=sigval("SIGINT")$val);
> for (kk in 1:100) { print(kk); }
> }, interrupt=function(int) {
> print(int);
> })
>
> which gives:
>
> [1] "Tic"
> [1] "Tac"
> [1] 1
> [1] 2
> [1] 3
> [1] 4
> [1] 5
> [1] 6
> [1] 7
> [1] 8
> [1] 9
> [1] 10
> [1] 11
> [1] 12
> <interrupt: >
>
> Interestingly, the SIGINT signal is not interrupting R momentarily,
> which is why the code following kill() is still executed for a while
> before the interrupt is caught.
>
> /Henrik
>
> On Wed, Nov 3, 2010 at 5:06 PM, Henrik Bengtsson <hb at biostat.ucsf.edu> wrote:
>> Hi,
>>
>> I am also interest in ways to in R send signals to other R
>> sessions/processes, ideally in (what appears to be) an OS-independent
>> way. For what it is worth, related question have been asked before,
>> cf. R-devel thread 'Sending signals to current R process from R
>> running under MS Windows (c.f. Esc)' started on 2009-11-28:
>>
>> http://www.mail-archive.com/r-devel@r-project.org/msg18790.html
>>
>> Still no workable suggestions/solutions AFAIK.
>>
>> /Henrik
>>
>> On Wed, Nov 3, 2010 at 2:55 PM, Steve Lianoglou
>> <mailinglist.honeypot at gmail.com> wrote:
>>> Hi all,
>>>
>>> Sometimes I'll find myself "ctrl-c"-ing like a madman to kill some
>>> code that's parallelized via foreach/doMC when I realized that I just
>>> set my cpu off to do something boneheaded, and it will keep doing that
>>> thing for a while.
>>>
>>> In these situations, since I interrupted its normal execution,
>>> foreach/doMC doesn't "clean up" after itself by killing the processes
>>> that were spawned. Furthermore, I believe that when I quit my "main" R
>>> session, the spawned processes still remain (there, but idle).
>>>
>>> I can go in via terminal (or some task manager/activity monitor) and
>>> kill them manually, but does foreach (or something else (maybe
>>> multicore?)) keep track of the process IDs that it spawned?
>>>
>>> Is there some simple doCleanup() function I can write to get these R
>>> processes and kill them automagically?
>>>
>>> For what it's worth, I'm running on linux & os x, R-2.12 and the
>>> latest versions of foreach/doMC/multicore (though, I feel like this
>>> has been true since I've started using foreach/doMC way back when).
>>>
>>> Thanks,
>>> -steve
>>>
>>> --
>>> Steve Lianoglou
>>> Graduate Student: Computational Systems Biology
>>> | Memorial Sloan-Kettering Cancer Center
>>> | Weill Medical College of Cornell University
>>> Contact Info: http://cbio.mskcc.org/~lianos/contact
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>
--
Steve Lianoglou
Graduate Student: Computational Systems Biology
| Memorial Sloan-Kettering Cancer Center
| Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact
More information about the R-help
mailing list