Skip to content
Prev 56874 / 63421 Next

[External] make running on.exit expr uninterruptible

suspendInterrupts has dynamic extent, so you need to make sure it
covers the entire computation. Defining your f like this is one option:

f <- function() {
     ff <- function() {
         on.exit(cntr_on.exit <<- cntr_on.exit + 1L)
         cntr_f <<- cntr_f + 1L
         ## allowInterrupts(... interruptable stuff ...)
         TRUE
     }
     suspendInterrupts(ff())
}

You can move the suspendInterrupts higher up in the computation, but
then it becomes more important to use allowInterrupts at appropriate
points.

It would be possible to have R suspend interrupts around function
calling infrastructure to provide stronger guarantees about
non-interruptable on.exit/finally actions, but there are both upsides
and downsides to doing that.

Best,

luke
On Wed, 22 May 2019, Andreas Kersting wrote: