Created
September 13, 2013 21:54
-
-
Save yaauie/6556591 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'thread' | |
require 'timeout' | |
module NoTimeout | |
extend self | |
def no_timeout | |
current_thread_eigenclass = (class << Thread.current; self; end) | |
original_raise_method = current_thread_eigenclass.instance_exec do | |
method(:raise).tap do |original_raise_method| | |
define_method :raise do |*args| | |
if Timeout::Error == args.first || args.first <= Timeout::ExitException | |
$stderr.puts "Timeout::Error was raised and squashed." | |
else | |
original_raise_method.call(*args) | |
end | |
end | |
end | |
end | |
return yield | |
ensure | |
current_thread_eigenclass.instance_exec do | |
define_method(:raise, &original_raise_method) | |
end | |
end | |
end | |
# usage | |
Timeout.timeout(x) do | |
NoTimeout::no_timeout { binding.pry } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment