i have this piece of code:
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
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.
Am I doing something wrong?
The problem is that
platform.search
is catching the exception thatTimeout#timeout throws
.You can get around this by wrapping your inner code in another thread -- YMMV.
Your code is correct
does print out "print me something please".
Try the basic code as above. If that works, you have an issue in
platform.search
.According to the documentation:
This means it only returns true if it's successful, otherwise the variable will not be set (ie it's nil NOT false).
As far as your example goes, it's definitely timing out for me and getting to the rescue part...