rlang icon indicating copy to clipboard operation
rlang copied to clipboard

Helper for interrupt capturing functions

Open hadley opened this issue 6 months ago • 1 comments

If you're capturing interrupts, I suspect it's useful to include a get-out-of-jail free card like this:

check_repeated_interrupt <- function() {
  if (Sys.time() - the$last_interrupt < 1) {
    cli::cli_alert_warning("Interrupting")
    interrupt()
  }
  the$last_interrupt <- Sys.time()
}

Otherwise if that function is nested inside a loop, or worse another interrupt capturing function, you really have to hammer Ctrl + C to get an interrupt at exactly the right time.

I hit this in ellmer where I had a loop around httr2::req_perform_parallel() and I found it very hard to escape from.

hadley avatar Jun 18 '25 14:06 hadley

Reminds me Ctrl+G in emacs which is used to interrupt. Emacs code is free to inhibit interrupts within a context but if the user hits Ctrl+G three times in a row, the core event loop issues a hard interrupt that can't be inhibited by user code.

lionel- avatar Jun 23 '25 08:06 lionel-