[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

open-uri timeout

Jeff Schwab

8/16/2006 9:48:00 PM

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.

2 Answers

Ara.T.Howard

8/16/2006 10:06:00 PM

0

Jeff Schwab

8/16/2006 10:26:00 PM

0


ara.t.howard@noaa.gov 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.

> the simple way is
>
> require 'timeout'
>
> retries = 42
>
> begin
> Timeout::timeout(s){
> open('http://a.ur...) do |f|
> # ... stuff with f
> 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.