lib/timeout.rb: fallback to Timeout::Error
* lib/timeout.rb (Timeout::ExitException.catch): pass arguments for new instance. * lib/timeout.rb (Timeout::ExitException#exception): fallback to Timeout::Error if couldn't throw. [ruby-dev:47872] [Bug #9380] * lib/timeout.rb (Timeout#timeout): initialize ExitException with message for the fallback case. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44523 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
38e89273ed
commit
3e9e4a6a96
11
ChangeLog
11
ChangeLog
@ -1,3 +1,14 @@
|
|||||||
|
Wed Jan 8 13:12:41 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/timeout.rb (Timeout::ExitException.catch): pass arguments
|
||||||
|
for new instance.
|
||||||
|
|
||||||
|
* lib/timeout.rb (Timeout::ExitException#exception): fallback to
|
||||||
|
Timeout::Error if couldn't throw. [ruby-dev:47872] [Bug #9380]
|
||||||
|
|
||||||
|
* lib/timeout.rb (Timeout#timeout): initialize ExitException with
|
||||||
|
message for the fallback case.
|
||||||
|
|
||||||
Tue Jan 7 12:43:06 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Tue Jan 7 12:43:06 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* lib/timeout.rb (Timeout#timeout): should not rescue ordinarily
|
* lib/timeout.rb (Timeout#timeout): should not rescue ordinarily
|
||||||
|
@ -28,15 +28,23 @@ module Timeout
|
|||||||
class ExitException < ::Exception # :nodoc:
|
class ExitException < ::Exception # :nodoc:
|
||||||
attr_reader :thread
|
attr_reader :thread
|
||||||
|
|
||||||
def self.catch
|
def self.catch(*args)
|
||||||
exc = new
|
exc = new(*args)
|
||||||
exc.instance_variable_set(:@thread, Thread.current)
|
exc.instance_variable_set(:@thread, Thread.current)
|
||||||
exc.freeze
|
exc.freeze
|
||||||
::Kernel.catch(exc) {yield exc}
|
::Kernel.catch(exc) {yield exc}
|
||||||
end
|
end
|
||||||
|
|
||||||
def exception(*)
|
def exception(*)
|
||||||
throw(self, caller) if self.thread == Thread.current
|
if self.thread == Thread.current
|
||||||
|
bt = caller
|
||||||
|
begin
|
||||||
|
throw(self, bt)
|
||||||
|
rescue ArgumentError => e
|
||||||
|
raise unless e.message.start_with?("uncaught throw")
|
||||||
|
raise Error, message, backtrace
|
||||||
|
end
|
||||||
|
end
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -95,7 +103,7 @@ module Timeout
|
|||||||
bt = e.backtrace
|
bt = e.backtrace
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
bt = ExitException.catch(&bl)
|
bt = ExitException.catch(message, &bl)
|
||||||
end
|
end
|
||||||
rej = /\A#{Regexp.quote(__FILE__)}:#{__LINE__-4}\z/o
|
rej = /\A#{Regexp.quote(__FILE__)}:#{__LINE__-4}\z/o
|
||||||
bt.reject! {|m| rej =~ m}
|
bt.reject! {|m| rej =~ m}
|
||||||
|
@ -75,4 +75,15 @@ class TestTimeout < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_enumerator_next
|
||||||
|
bug9380 = '[ruby-dev:47872] [Bug #9380]: timeout in Enumerator#next'
|
||||||
|
e = (o=Object.new).to_enum
|
||||||
|
def o.each
|
||||||
|
sleep
|
||||||
|
end
|
||||||
|
assert_raise_with_message(Timeout::Error, 'execution expired', bug9380) do
|
||||||
|
Timeout.timeout(0.01) {e.next}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user