开发者

rescue Timeouts with SystemTimer

开发者 https://www.devze.com 2023-02-10 04:47 出处:网络
I\'m using the SystemTimer gem to开发者_运维问答 deal with timeout problems. https://github.com/ph7/system-timer

I'm using the SystemTimer gem to开发者_运维问答 deal with timeout problems. https://github.com/ph7/system-timer

I can't find a way to catch the Exception when a Timeout

begin
  SystemTimer.timeout_after(10.seconds) do
    # facebook api
    rest_graph.fql(query)
  end
rescue RestGraph::Error::InvalidAccessToken
  return nil
rescue Timeout::Error
  # never executed
end

But the last Exception Timeout::Error is never triggered.


Why not use Timeout, which comes with 1.9.2 and is designed to do this?

require 'timeout'
status = Timeout::timeout(5) {
  # Something that should be interrupted if it takes too much time...
}


Try this: (based on your link)

class TimedOut < StandardError
end

begin
  SystemTimer.timeout_after(10.seconds, TimedOut) do
    # ...
  end
rescue TimedOut
  # ...
end
0

精彩评论

暂无评论...
验证码 换一张
取 消