From pdalgd at gmail.com  Wed Oct 26 22:34:21 2016
From: pdalgd at gmail.com (peter dalgaard)
Date: Wed, 26 Oct 2016 22:34:21 +0200
Subject: [Rd] BUG?: On Linux setTimeLimit() fails to propagate timeout
	error when it occurs (works on Windows)
In-Reply-To: <CAFDcVCQmAAq_GYB5WUE2O25RkzCCpeMudJwQ3pCucp5MATAkXw@mail.gmail.com>
References: <CAFDcVCStodbQMS4TffimW69qvVutCX8FheDNxf1o_Ejpmu9NQg@mail.gmail.com>
	<8995051E-628D-4536-A64C-517A9188F416@xs4all.nl>
	<CAFDcVCQmAAq_GYB5WUE2O25RkzCCpeMudJwQ3pCucp5MATAkXw@mail.gmail.com>
Message-ID: <57E7E96A-D3F9-42F4-877D-56109CD38CC8@gmail.com>

Spencer also had tools and rsconnect loaded (via a namespace) but it doesn't seem to make a difference for me if I load them. It also doesn't seem to matter for me whether it is CRAN R, locally built R, Terminal, R.app. However, RStudio differs 

> setTimeLimit(elapsed=1)
Error: reached elapsed time limit
> setTimeLimit(elapsed=1)
Error: reached elapsed time limit
> setTimeLimit(elapsed=1); system.time({Sys.sleep(10);message("done")})
Error in Sys.sleep(10) : reached elapsed time limit
Timing stopped at: 0.003 0.003 0.733 

-pd


> On 26 Oct 2016, at 21:54 , Henrik Bengtsson <henrik.bengtsson at gmail.com> wrote:
> 
> Thank you for the feedback and confirmations.  Interesting to see that
> it's also reproducible on macOS expect for Spencer; that might
> indicate a difference in builds.
> 
> BTW, my original post suggested that timeout error was for sure
> detected while running Sys.sleep(10).  However, it could of course
> also be that it is only detected after it finishes.
> 
> 
> For troubleshooting, the help("setTimeLimit", package = "base") says that:
> 
> * "Time limits are checked whenever a user interrupt could occur. This
> will happen frequently in R code and during Sys.sleep, but only at
> points in compiled C and Fortran code identified by the code author."
> 
> The example here uses Sys.sleep(), which supports and detects user interrupts.
> 
> 
> The timeout error message is thrown by the R_ProcessEvents(void)
> function as defined in:
> 
> * src/unix/sys-unix.c
> (https://github.com/wch/r-source/blob/trunk/src/unix/sys-unix.c#L421-L453)
> * src/gnuwin32/system.c
> (https://github.com/wch/r-source/blob/trunk/src/gnuwin32/system.c#L110-L140)
> 
> So, they're clearly different implementations on Windows and Unix.
> Also, for the Unix implementation, the code differ based on
> preprocessing directive HAVE_AQUA, which could explain why Spencer
> observes a different behavior than Peter and Berend (all on macOS).
> 
> 
> Whenever the R_CheckUserInterrupt() function is called it in turn
> always calls R_ProcessEvents().  At the end, there is a code snippet -
> if (R_interrupts_pending) onintr(); - which is Windows specific and
> could be another important difference between Windows and Unix.  This
> function is defined in:
> 
> * src/main/errors.c
> (https://github.com/wch/r-source/blob/trunk/src/main/errors.c#L114-L134)
> 
> 
> The do_setTimeLimit() function controls global variables cpuLimitValue
> and elapsedLimitValue, which are checked in R_ProcessEvents(), but
> other than setting the timeout limits I don't think it's involved in
> the runtime checks. The do_setTimeLimit() is defined in:
> 
> * src/main/sysutils.c
> (https://github.com/wch/r-source/blob/trunk/src/main/sysutils.c#L1692-L1736)
> 
> 
> Unfortunately, right now, I've got little extra time to troubleshoot
> this further.
> 
> /Henrik
> 
> On Wed, Oct 26, 2016 at 2:22 AM, Berend Hasselman <bhh at xs4all.nl> wrote:
>> 
>>> On 26 Oct 2016, at 04:44, Henrik Bengtsson <henrik.bengtsson at gmail.com> wrote:
>>> .......
>>> This looks like a bug to me.  Can anyone on macOS confirm whether this
>>> is also a problem there or not?
>>> 
>> 
>> 
>> Tried it on macOS El Capitan and got this (running in R.app with R version 3.3.2 RC (2016-10-23 r71574):
>> 
>>> setTimeLimit(elapsed=1)
>>> system.time({ Sys.sleep(10); message("done") })
>> Error in Sys.sleep(10) : reached elapsed time limit
>> Timing stopped at: 0.113 0.042 10.038
>> 
>> Berend
>> 
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



[Rd] BUG?: On Linux setTimeLimit() fails to propagate timeout error when it occurs (works on Windows)
peter dalgaard