I'm still new to Ruby, and the first time I'm trying to use Timeout for some HTTP functions, but obviously I'm missing a mark somewhere. My code is below, but it does not work. Instead, the following exception occurs:
C:/Ruby193/lib/ruby/1.9.1/net/http.rb:762:in `initialize': execution expired (Timeout::Error)
Which does not make much sense to me, since the part of the code that he chooses is wrapped in a begin / rescue / end block and, in particular, will save Timeout :: Error. Am I doing something wrong or something that is not supported in Ruby?
retries = 10 Timeout::timeout(5) do begin File.open("#{$temp}\\http.log", 'w') { |f| http.request(request) do |str| f.write str.body end } rescue Timeout::Error if retries > 0 print "Timeout - Retrying..." retries -= 1 retry else puts "ERROR: Not responding after 10 retries! Giving up!") exit end end end
source share