aboutsummaryrefslogtreecommitdiffstats
path: root/lib/timeout.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-07 05:04:02 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-07 05:04:02 +0000
commit08f0db2c68a9e306f3a637e9d32d9e7b8b1f2e92 (patch)
treef62afb5ed192f0bd674762fb6063c4a224649b9f /lib/timeout.rb
parent9dd64b6053685a4db7d4e60d16b0fc090384dae0 (diff)
downloadruby-08f0db2c68a9e306f3a637e9d32d9e7b8b1f2e92.tar.gz
timeout.rb: replace deferred exception after async_interrupt_timing
* lib/timeout.rb (Timeout#timeout): since async_interrupt_timing re-raises a deferred exception, replace the timeout exception with Timeout::Error after it. [Bug #7503] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38255 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/timeout.rb')
-rw-r--r--lib/timeout.rb26
1 files changed, 13 insertions, 13 deletions
diff --git a/lib/timeout.rb b/lib/timeout.rb
index ee20115754..127bccf924 100644
--- a/lib/timeout.rb
+++ b/lib/timeout.rb
@@ -50,8 +50,8 @@ module Timeout
def timeout(sec, klass = nil, immediate: false) #:yield: +sec+
return yield(sec) if sec == nil or sec.zero?
exception = klass || Class.new(ExitException)
- Thread.async_interrupt_timing(exception => immediate ? :immediate : :on_blocking) do
- begin
+ begin
+ Thread.async_interrupt_timing(exception => immediate ? :immediate : :on_blocking) do
begin
x = Thread.current
y = Thread.start {
@@ -70,18 +70,18 @@ module Timeout
y.join # make sure y is dead.
end
end
- rescue exception => e
- rej = /\A#{Regexp.quote(__FILE__)}:#{__LINE__-4}\z/o
- (bt = e.backtrace).reject! {|m| rej =~ m}
- level = -caller(CALLER_OFFSET).size
- while THIS_FILE =~ bt[level]
- bt.delete_at(level)
- level += 1
- end
- raise if klass # if exception class is specified, it
- # would be expected outside.
- raise Error, e.message, e.backtrace
end
+ rescue exception => e
+ rej = /\A#{Regexp.quote(__FILE__)}:#{__LINE__-4}\z/o
+ (bt = e.backtrace).reject! {|m| rej =~ m}
+ level = -caller(CALLER_OFFSET).size
+ while THIS_FILE =~ bt[level]
+ bt.delete_at(level)
+ level += 1
+ end
+ raise if klass # if exception class is specified, it
+ # would be expected outside.
+ raise Error, e.message, e.backtrace
end
end