When does RStudio's Stop button fail to interrupt a running computation?
20.5K reputation · 09 Sept 2022, 11:34 UTC
I run long computations in the RStudio console and rely on the Stop button (or Esc) to cancel them. Sometimes the interrupt works immediately; other times the session appears unresponsive and my only apparent recourse is Terminate R, which discards the workspace.
My understanding is that Stop sends an interrupt that R only honors when the interpreter checks for it, so code executing inside compiled C/C++/Fortran routines that never call R_CheckUserInterrupt() will not stop until control returns to R. I also believe operations blocked in certain system calls may ignore the request entirely, and that behavior differs between Windows and Unix-like systems.
Since RStudio has no built-in per-command timeout, I am weighing setTimeLimit() against package-level timeout wrappers, but I am unsure how reliably either fires while native code is running.
Which categories of long-running operations are known to ignore the Stop interrupt? Does setTimeLimit(elapsed = ...) fire reliably when execution is inside compiled code? Is there any way to predict, before launching a computation, whether cancellation will be graceful?