Skip to content

Instantly share code, notes, and snippets.

@yaauie
Created September 13, 2013 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaauie/6556591 to your computer and use it in GitHub Desktop.
Save yaauie/6556591 to your computer and use it in GitHub Desktop.
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