Open-uri timeout

I love open-uri, but does anyone know how to configure the time-out
before open() will throw a Timeout::Error? I’d like to make it
shorter.

I’m trying to download some documents from a server that sometimes
works fine, but other times seems to ignore HTTP requests entirely. If
a download doesn’t begin after a few seconds, I want to give up on the
request and try again. Ideas are welcome.

On Thu, 17 Aug 2006, Jeffrey wrote:

I love open-uri, but does anyone know how to configure the time-out
before open() will throw a Timeout::Error? I’d like to make it
shorter.

I’m trying to download some documents from a server that sometimes
works fine, but other times seems to ignore HTTP requests entirely. If
a download doesn’t begin after a few seconds, I want to give up on the
request and try again. Ideas are welcome.

the simple way is

require ‘timeout’

retries = 42

begin
Timeout::timeout(s){
open(‘http://a.url.com’) do |f|
# … stuff with f
end
}
rescue Timeout::Error
retries -= 1
if retry > 0
sleep 0.42 and retry
else
raise
end
end

-a

[email protected] wrote:

On Thu, 17 Aug 2006, Jeffrey wrote:

I love open-uri, but does anyone know how to configure the time-out
before open() will throw a Timeout::Error? I’d like to make it
shorter.

   end
 }

rescue Timeout::Error
retries -= 1
if retry > 0
sleep 0.42 and retry
else
raise
end
end

Thanks, that’s great. It seems to be working.