From ripley at stats.ox.ac.uk  Sat May  5 10:34:51 2007
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Sat, 5 May 2007 09:34:51 +0100 (BST)
Subject: [Rd] sending signals to embedded R
In-Reply-To: <Pine.LNX.4.64.0705041828340.32397@itasca2.wildberry.org>
References: <eb555e660705041448h27679664o21522a5d04285d74@mail.gmail.com>
	<Pine.LNX.4.64.0705042309520.21366@gannet.stats.ox.ac.uk>
	<eb555e660705041534r32c2d62di7309b5a457456c7c@mail.gmail.com>
	<Pine.LNX.4.64.0705041828340.32397@itasca2.wildberry.org>
Message-ID: <Pine.LNX.4.64.0705050910190.1517@gannet.stats.ox.ac.uk>

On Fri, 4 May 2007, Luke Tierney wrote:

> On Fri, 4 May 2007, Deepayan Sarkar wrote:
>
>> On 5/4/07, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
>>> On Fri, 4 May 2007, Deepayan Sarkar wrote:
>>> 
>>>> one thing I haven't been able to figure out from R-exts is how to
>>>> interrupt a calculation running inside an embedded R. C code inside R
>>>> calls R_CheckUserInterrupt() intermittently to check for interrupts,
>>>> but how does my GUI tell R that the user wants it interrupted?
>>> 
>>> Well, the intention is that you send an interrupt, which hardly needs to
>>> be in the manual.
>> 
>> I didn't mean to imply that it does. I'm just new to signals and
>> things that should be obvious aren't.
>> 
>> Basically kill(2) seems to be the right thing to use, but I wasn't
>> sure what the PID needs to be. Turns out sending SIGINT to my GUI from
>> a shell interrupts R, so raise(SIGINT) should be enough.
>
> The tricky bit here is figuring out who does the sending.  It you have
> a separate thread/process for the GUI and R then that is fine (though
> may raise other issues).  If it is a single thread then you need your
> event processing to get an occasional look in to recognise the user
> action that triggers an interrupt. The Windows version handles this by
> having R_CheckUserInterrupt() do a limited amount of event processing
> (you need to be careful in GUI events have R actions associated with
> them).  I believe the Mac version is similar though it has been a

I was assuming that Deepayan's GUI (which seems to need Qt4, BTW, so I was 
unable to compile it) worked via the R-Unix eventloop, in which case it 
gets some CPU time from time to time.

gnomeGUI has an interrupt menu item with action 'onintr', which may well 
be what Deepayan is looking for: the only reason that package still exists 
is to provide example code.  (Not that it was ever properly integrated 
with the R event loop.)

If the issue is what happens when the user Ctrl-C's in the GUI console, 
that depends on what the GUI toolkit does with keyboard input: if it 
generates a SIGINT this should just work, but otherwise the keyboard 
handler needs to be told to call onintr() one way or another.


> while since I looked at that. I don't believe the unix version of
> R_CheckUserInterrupt() does not provide hooks for installing such
> checking (we have talked about this off an on but I don't believe
> anything happened -- could be wrong there though).
>
> If Qt allows this one option may be to have events on your nterrupt
> widget managed by a small thread that does nothing other than send a
> signal to the main thread if the widget is clicked.
>
> Best,
>
> luke
>
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] sending signals to embedded R
Prof Brian Ripley