[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Net::HTTP timeout

Alexandru E. Ungur

3/22/2006 9:45:00 AM

Hi all,

Is there a way to set the timout limit that affects Net::HTTP ?
This is what I'm trying to do:

body = Net::HTTP.get(URI.parse(url))

and I do know that the target script (url) takes a long time to do
its processing and to return the data to the calling script, so
that's why I want get() to ignore any timeouts (or to set them high
enough).

This is what I get right now:

/usr/lib/ruby/1.8/net/protocol.rb:197:in `rbuf_fill': socket read timeout (60
sec) (Timeout::Error)
from /usr/lib/ruby/1.8/net/protocol.rb:160:in `readuntil'
from /usr/lib/ruby/1.8/net/protocol.rb:171:in `readline'
from /usr/lib/ruby/1.8/net/http.rb:1760:in `read_chunked'
from /usr/lib/ruby/1.8/net/http.rb:1739:in `read_body_0'
from /usr/lib/ruby/1.8/net/http.rb:1705:in `read_body'
from /usr/lib/ruby/1.8/net/http.rb:1730:in `body'
from /usr/lib/ruby/1.8/net/http.rb:1668:in `reading_body'
from /usr/lib/ruby/1.8/net/http.rb:835:in `request'
from /usr/lib/ruby/1.8/net/http.rb:297:in `get_by_uri'
from /usr/lib/ruby/1.8/net/http.rb:296:in `start'
from /usr/lib/ruby/1.8/net/http.rb:296:in `get_by_uri'
from /usr/lib/ruby/1.8/net/http.rb:282:in `get_response'
from /usr/lib/ruby/1.8/net/http.rb:263:in `get'
from jobqueue.rb:41



Any tips/pointers are appreciated, thank you,
Alex

P.S. I did read http://www.ruby-doc.o... -> net/http but
haven't seen any method/parameter that might help me on this...


5 Answers

Bob Gustafson

3/22/2006 12:04:00 PM

0

You could search the source for '60'. And/or 'Timeout::Error'

On Wed, 2006-03-22 at 18:44 +0900, Alexandru E. Ungur wrote:
> Hi all,
>
> Is there a way to set the timout limit that affects Net::HTTP ?
> This is what I'm trying to do:
>
> body = Net::HTTP.get(URI.parse(url))
>
> and I do know that the target script (url) takes a long time to do
> its processing and to return the data to the calling script, so
> that's why I want get() to ignore any timeouts (or to set them high
> enough).
>
> This is what I get right now:
>
> /usr/lib/ruby/1.8/net/protocol.rb:197:in `rbuf_fill': socket read timeout (60
> sec) (Timeout::Error)
> from /usr/lib/ruby/1.8/net/protocol.rb:160:in `readuntil'
> from /usr/lib/ruby/1.8/net/protocol.rb:171:in `readline'
> from /usr/lib/ruby/1.8/net/http.rb:1760:in `read_chunked'
> from /usr/lib/ruby/1.8/net/http.rb:1739:in `read_body_0'
> from /usr/lib/ruby/1.8/net/http.rb:1705:in `read_body'
> from /usr/lib/ruby/1.8/net/http.rb:1730:in `body'
> from /usr/lib/ruby/1.8/net/http.rb:1668:in `reading_body'
> from /usr/lib/ruby/1.8/net/http.rb:835:in `request'
> from /usr/lib/ruby/1.8/net/http.rb:297:in `get_by_uri'
> from /usr/lib/ruby/1.8/net/http.rb:296:in `start'
> from /usr/lib/ruby/1.8/net/http.rb:296:in `get_by_uri'
> from /usr/lib/ruby/1.8/net/http.rb:282:in `get_response'
> from /usr/lib/ruby/1.8/net/http.rb:263:in `get'
> from jobqueue.rb:41
>
>
>
> Any tips/pointers are appreciated, thank you,
> Alex
>
> P.S. I did read http://www.ruby-doc.o... -> net/http but
> haven't seen any method/parameter that might help me on this...


Alexandru E. Ungur

3/22/2006 12:51:00 PM

0

>>> sender: "Bob Gustafson" date: "Wed, Mar 22, 2006 at 09:04:17PM +0900" <<<EOQ
> You could search the source for '60'. And/or 'Timeout::Error'
Well, I was hoping for a more ruby-like ideea .set_timeout() or something
but this will do just fine, thanks for the ideea :)

Alex


Dimitri Aivaliotis

3/22/2006 2:15:00 PM

0

On 3/22/06, Alexandru E. Ungur <alexandru@globalterrasoft.ro> wrote:

> body = Net::HTTP.get(URI.parse(url))
>
> and I do know that the target script (url) takes a long time to do
> its processing and to return the data to the calling script, so
> that's why I want get() to ignore any timeouts (or to set them high
> enough).

Have you tried the following?
(from "Example 3: More generic GET+print" in the docs)

require 'net/http'
require 'uri'

url = URI.parse('http://www.example.com/index...)

res = Net::HTTP.start(url.host, url.port) {|http|
http.read_timeout = 600
http.get('/index.html')
}

body = res.body

- Dimitri


Chintan Trivedi

3/23/2006 11:00:00 AM

0

Use Time Out block.

require 'timeout'

...
...
begin
timeout(60) do
resp, body=h.get('/index.html')
puts body
end
rescue TimeoutError
puts "Timed Out"
end




On 3/22/06, Alexandru E. Ungur <alexandru@globalterrasoft.ro> wrote:
>
> Hi all,
>
> Is there a way to set the timout limit that affects Net::HTTP ?
> This is what I'm trying to do:
>
> body = Net::HTTP.get(URI.parse(url))
>
> and I do know that the target script (url) takes a long time to do
> its processing and to return the data to the calling script, so
> that's why I want get() to ignore any timeouts (or to set them high
> enough).
>
> This is what I get right now:
>
> /usr/lib/ruby/1.8/net/protocol.rb:197:in `rbuf_fill': socket read timeout
> (60
> sec) (Timeout::Error)
> from /usr/lib/ruby/1.8/net/protocol.rb:160:in `readuntil'
> from /usr/lib/ruby/1.8/net/protocol.rb:171:in `readline'
> from /usr/lib/ruby/1.8/net/http.rb:1760:in `read_chunked'
> from /usr/lib/ruby/1.8/net/http.rb:1739:in `read_body_0'
> from /usr/lib/ruby/1.8/net/http.rb:1705:in `read_body'
> from /usr/lib/ruby/1.8/net/http.rb:1730:in `body'
> from /usr/lib/ruby/1.8/net/http.rb:1668:in `reading_body'
> from /usr/lib/ruby/1.8/net/http.rb:835:in `request'
> from /usr/lib/ruby/1.8/net/http.rb:297:in `get_by_uri'
> from /usr/lib/ruby/1.8/net/http.rb:296:in `start'
> from /usr/lib/ruby/1.8/net/http.rb:296:in `get_by_uri'
> from /usr/lib/ruby/1.8/net/http.rb:282:in `get_response'
> from /usr/lib/ruby/1.8/net/http.rb:263:in `get'
> from jobqueue.rb:41
>
>
>
> Any tips/pointers are appreciated, thank you,
> Alex
>
> P.S. I did read http://www.ruby-doc.o... -> net/http but
> haven't seen any method/parameter that might help me on this...
>
>

Alexandru E. Ungur

3/23/2006 11:20:00 AM

0

Thank you all for your help!

In the end .read_timeout did the trick just fine :)

Thanks,
Alex