[Rd] on.exit() handler being interrupted by time limit

Tomas Kalibera tom@@@k@||ber@ @end|ng |rom gm@||@com
Mon May 12 16:41:06 CEST 2025


On 4/27/25 22:19, Duncan Murdoch wrote:
>
> BTW, the help for setTimeLimit() says that the time limit check 
> happens frequently during `Sys.sleep()`, but that doesn't appear to be 
> true. I've tried a variation on the code above which sleeps for 20 
> seconds, even with a time limit of 1 second.

Regarding base R, this works for me in Linux:

 > setTimeLimit(elapsed=10)
 > for(i in 1:1000) Sys.sleep(0.1)
Error in Sys.sleep(0.1) : reached elapsed time limit

That is,  the loop gets interrupted after about 10s.

Reading the code of R, there is a check in Sys.sleep(), but only after 
the first wait (in a loop, iteratively waiting for the required 
duration). When polled events are not active, the first wait is the 
whole duration.

I would read the documentation of ?setTimeLimit as that the check 
happens during Sys.sleep(), but not necessarily frequently, that 
"frequently" only refers to R code. And then the documentation would 
seem correct (or at least not contradicted). On the other hand, right, 
we could change Rsleep() to use a shorter sleep when elapsed time limit 
is in place, and that wouldn't contradict the documentation, either.

Best
Tomas


>
> Duncan Murdoch
>
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list