Skip to content

Instantly share code, notes, and snippets.

@jjb
Created September 16, 2012 01:32
Show Gist options
  • Save jjb/3730697 to your computer and use it in GitHub Desktop.
Save jjb/3730697 to your computer and use it in GitHub Desktop.
Timeout raising an error wherever the inner code happens to be
require 'timeout'
Timeout.timeout(rand) do # random number between 0 and 1 (seconds)
sleep 0.1
sleep 0.1
sleep 0.1
sleep 0.1
sleep 0.1
sleep 0.1
sleep 0.1
sleep 0.1
sleep 0.1
sleep 0.1
end
➔ ruby code.rb
code.rb:5:in `sleep': execution expired (Timeout::Error)
from code.rb:5:in `block in <main>'
from code.rb:3:in `<main>'
➔ ruby code.rb
code.rb:6:in `sleep': execution expired (Timeout::Error)
from code.rb:6:in `block in <main>'
from code.rb:3:in `<main>'
➔ ruby code.rb
code.rb:10:in `sleep': execution expired (Timeout::Error)
from code.rb:10:in `block in <main>'
from code.rb:3:in `<main>'
➔ ruby code.rb
code.rb:4:in `sleep': execution expired (Timeout::Error)
from code.rb:4:in `block in <main>'
from code.rb:3:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment