[Rd] terminating R code evalutation asynchronously

Christian Ledergerber christian.ledergerber at comerge.net
Tue Apr 21 10:45:08 CEST 2009


Hi, 

I am new to this mailing list. Hence brief a introduction: I am working for
Comerge, developing an online trading platform (interacting with brokers
over the internet in realtime) which is mostly written in Pascal. We are
using R-embedded to offer the user a way to implement strategies in R and
test them. 

Currently we are facing the following problem: We need to implement an
emergency exit procedure. The idea is that we send the process a signal
(like Crtl-C) and do all the necessary cleanup after the signal has been
caught. There are a number of constraints and wishes: 

1. The signal handler should take only very little time. E.g. set a number
of flags etc. and then return and leave the rest of the work to the main
program. 
2. The signal handler is asynchronous by nature. 
3. We would like that this works even if the user is hanging in an infinite
loop in the R code. E.g. we need to kill the current R code evaluation in
the signal handler. 
4. The main program needs to keep running to finish the cleanup. 

I found that the following function which seems to do the trick:
jump_to_toplevel() however, I am unsure whether this is safe - e.g. is this
function "thread safe" or do we risk that the application crashes when the
signal handler is invoked? Is there another, safer way to terminate the
current R execution? Furthermore this function seems to crash if the R
engine is not currently inside a R_tryEval call.

Thanks! 

Christian Ledergerber



More information about the R-devel mailing list