I am writing a function that needs to catch a rate-limiting error while pinging a web-based API.
I am using tryCatch to catch the error, and inside this function I specify the following error function:
error=function(e) {
warning(paste(e,"\nWaiting an hour for rate limit to reset..."))
Sys.sleep(3600) # Wait an hour for rate-limit to reset
return(user.info(user, ego.count))
}
The function appears to work, but when checking the output logs for the script I notice that the warning message is not written until after the sleep time has run out.
I can reproduce this behavior at the R console with:
print("Drew sucks")
Sys.sleep(10)
Ten seconds pass before Drew sucks is printed to the console. In my function, I would like to provide some feedback to the user about this long pause before the pause happens.
What is causing this behavior?
For the hell of it, try:
Assuming you’ve got the usual *NIX sleep command on path.