Attention is required, Timeout:: Error is not StandardError subclass, but the succession to the Interrupt class, so when caught, required special attention, presentation is as follows:
require 'net/pop3' begin Net::POP3.auth_only(@server, @port, @username, @password) rescue => e write_error_to_logfile(e) do_something_sensible end
Look above the code, when the POP3 server should not respond in a timely manner, when triggered by the following abnormalities can not be captured because the above said, look at the deal with the right code:
require 'net/pop3' begin Net::POP3.auth_only(@server, @port, @username, @password) rescue => e write_error_to_logfile(e) do_something_sensible rescue Timeout::Error => e write_error_to_logfile(e) do_something_sensible_for_timeout end
This code can work properly and in accordance with U.S. wishes to deal with the.
If you know each other's server would be more slow to respond, or you know the network status well, you can individually set the TimeOut time, the code is as follows:
require 'timeout'
...
...
begin
timeout(60) do
resp, body=3Dh.get('/index.html')
puts body
end
rescue TimeoutError
puts "Timed Out"
end Or this: (Source: http://textsnippets.com/posts/show/868)
http = Net::HTTP.new(url.host, url.port) http.read_timeout=time_out







