There are several ways to handle this.
Open-Uri and Net :: HTTP have timeout methods that then tell the underlying network stack how much time you are ready to wait. For example, Mechanize allows you to get your settings when you initialize an instance, for example:
mech = Mechanize.new { |agent| agent.open_timeout = 5 agent.read_timeout = 5 }
Everything is in the docs for new , but you will need to look at the source to see which instance variables you can get.
Or you can use the Ruby timeout module:
require 'timeout' status = Timeout::timeout(5) {
source share