http://github.com/jeremyd/terminator
terminator據說這定時的比較準,不過噁心的事,作者Readme上寫的例子不對,這Timeout錯誤一直沒有捕獲到
今天試了下,如下的代碼可以獲取的到這個錯誤
require "rubygems"
require "terminator"
def xx
raise "Other error"
end
Terminator.terminate 1 do
begin
xx
rescue Terminator::Error
p "timeout error"
rescue
p "Other error"
end
end
先暫時這樣,至於爲什麼只在裏面纔有用,以後再探求