[R-SIG-Mac] Sys.sleep() in R.app can't be interrupted

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Thu Apr 2 00:39:57 CEST 2026


As I've realized, my simple workaround is a little too simple, not 
necessarily matching the requested duration.  A better one looks at the 
elapsed time after the "one second" sleep.

Duncan Murdoch

On 2026-04-01 3:32 p.m., Duncan Murdoch wrote:
> This might be a well known issue, but I couldn't spot it in the FAQ or
> bug list or mailing list archives.
> 
> If you execute Sys.sleep(60) in R.app, the command can't be interrupted
> by ESC or Cmd-C until it is done.  R.app becomes completely unresponsive.
> 
> The number 60 isn't important, as far as I can tell this is true for any
> sleep time.
> 
> A simple workaround is to limit the duration of Sys.sleep() calls, e.g.
> using a function like this:
> 
>    Sleep <- function(duration) {
>     seconds <- floor(duration)
>     for (i in seq_len(seconds))
>       Sys.sleep(1)
>     Sys.sleep(duration - seconds)
>    }
> 
> R.app handles interrupts every time Sys.sleep returns, so this means the
> biggest delay is 1 second.
> 
> In case this isn't universal, here's my session info:
> 
> ```
> R version 4.5.3 (2026-03-11)
> Platform: aarch64-apple-darwin20
> Running under: macOS Sequoia 15.7.4
> 
> Matrix products: default
> BLAS:
> /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRblas.0.dylib
> 
> LAPACK:
> /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib;
>    LAPACK version 3.12.1
> 
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
> 
> time zone: America/Toronto
> tzcode source: internal
> 
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
> 
> loaded via a namespace (and not attached):
> [1] compiler_4.5.3
> ```
> 
> Duncan Murdoch



More information about the R-SIG-Mac mailing list