从可能很慢的网站读取数据时,我想确保get_response无法挂起,因此在x秒后添加了超时计时器。到现在为止还挺好。然后我读http://ph7spot.com/musings/system-timer这说明在某些情况下timer.rb不工作,因为ruby的线程实现。使用Net :: HTTP时,Rail定时器是否可靠?
有谁知道这是否是这些情况之一?
url = URI.parse(someurl)
begin
Timeout::timeout(30) do
response = Net::HTTP.get_response(url)
@responseValue = CGI.unescape(response.body)
end
rescue Exception => e
dosomething
end
不知何故,我的代码示例被消除了。 – Frank 2010-03-11 20:08:26
为你修复它。所有代码都需要缩进4(4)个空格。 – 2010-03-11 21:04:12
红宝石约定到2(两个)空格缩进 – shingara 2010-03-11 23:51:46