Ruby Timeout :: timeout不会引发异常,并且不会返回记录的内容 [英] Ruby Timeout::timeout doesn't fire Exception and doesn't return what documented

查看:234
本文介绍了Ruby Timeout :: timeout不会引发异常,并且不会返回记录的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码:

begin
  complete_results = Timeout.timeout(4) do      
    results = platform.search(artist, album_name)
  end
rescue Timeout::Error
  puts 'Print me something please'
end 

然后我启动包含此代码的方法,好了,这是堆栈跟踪的开始:

I then launch the method containing this code, and well, here is the beginning of a stack trace:


Exception message :  execution expired
Exception backtrace :  /***/****/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/timeout.rb:64:i

所以我天真的认为我的通话超时了.但是永远不会打印请给我打印一些东西",并且complete_results假定是超时状态返回值(如文档中所述,为true或false),绝对不是布尔值.

So i naively thinks that my call timeouted. But 'Print me something please' is never printed and complete_results wich is suppose to be the timeout status return value (either true or false, as mentionned in the documentation), is definitively not a boolean.

我做错什么了吗?

推荐答案

您的代码正确

require 'timeout'
begin
  complete_results = Timeout.timeout(1) do      
   sleep(2)
  end
rescue Timeout::Error
  puts 'Print me something please'
end

打印出请给我打印点东西".

does print out "print me something please".

尝试上面的基本代码.如果可行,则您在platform.search中遇到问题.

Try the basic code as above. If that works, you have an issue in platform.search.

这篇关于Ruby Timeout :: timeout不会引发异常,并且不会返回记录的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆