How to control timeout exceptions

This is code that i am using for fetching updates from twitter. I used
SystemTimer gem from
thoughtwork( to ensure that we
don’t get anymore timeout exception and crashed page.As article
( points out weaknesses of
timeout.rb implemented in ruby 1.8. We are using ruby 1.8 in production.
After system_timer we also handle “rescue Twitter::Error” but they also
didn’t work. I know we can also option to configure timeout in the http
client library but i think these both should work fine.

We are using rails 2.2.2 and ruby 1.8.6. Here is my code.


SystemTimer.timeout(TWITTER_SERVICE_TIMEOUT) do
c = =>,:password => profile_twitter.password)
my_timeline = c.timeline_for(:me, :since => 30.minutes.ago)
rescue Twitter::RESTError => re

rescue Timeout::Error
  #my_timeline = nil


Exception i got mostly

/usr/lib/ruby/1.8/net/http.rb:560:in initialize' /usr/lib/ruby/1.8/net/http.rb:560:inopen’
/usr/lib/ruby/1.8/net/http.rb:560:in connect' /usr/lib/ruby/1.8/timeout.rb:53:intimeout’
/usr/lib/ruby/1.8/timeout.rb:93:in timeout' /usr/lib/ruby/1.8/net/http.rb:560:inconnect’
/usr/lib/ruby/1.8/net/http.rb:553:in do_start' /usr/lib/ruby/1.8/net/http.rb:542:instart’
http_connect' /usr/lib/ruby/gems/1.8/gems/twitter4r-0.3.0/lib/twitter/client/timeline.rb:66:intimeline_for’

Maybe you want to check out Terminator? or

I cannot make promises but Ara is probably the guy to come up with a
solution for that kind of problem.


Toutes les grandes personnes ont d’abord été des enfants, mais peu
d’entre elles s’en souviennent.

All adults have been children first, but not many remember.

[Antoine de Saint-Exupéry]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs