Ruby 使用SystemTimer进行救援超时

Ruby 使用SystemTimer进行救援超时,ruby,timeout,Ruby,Timeout,我正在使用SystemTimer gem来处理超时问题。 我找不到在超时时捕获异常的方法 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 但

我正在使用SystemTimer gem来处理超时问题。

我找不到在超时时捕获异常的方法

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
但最后一个异常超时::错误从未触发。

尝试:(基于链接)

class TimedOut
试试这个:(根据你的链接)

class TimedOut
为什么不使用1.9.2附带的、专门为此设计的软件

require 'timeout'
status = Timeout::timeout(5) {
  # Something that should be interrupted if it takes too much time...
}
为什么不使用1.9.2附带的、专门为此设计的工具呢

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

[12:19][~]$ruby-vruby 1.8.7(2009-06-12修补级别174)[universal-darwin10.0][12:19][~]$ruby-vruby 1.8.7(2009-06-12修补级别174)[universal-darwin10.0]