summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-31 00:12:27 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-31 00:12:27 +0000
commit67cf90f6a4c74b3e5c881447ce9a762237d347a2 (patch)
treedf8a6febf9116fef71060182805801a0add28a92 /lib
parent0c9c99ab0244281f6d71b1bbae48377c6e1f7384 (diff)
merges r31623 from trunk into ruby_1_9_2.
-- * lib/timeout.rb (Timeout#timeout): don't leak "execution expired" exception. [Bug #4283] [ruby-core:34534]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@31837 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/timeout.rb32
1 files changed, 17 insertions, 15 deletions
diff --git a/lib/timeout.rb b/lib/timeout.rb
index 297b76936c..aa0e7576d5 100644
--- a/lib/timeout.rb
+++ b/lib/timeout.rb
@@ -44,17 +44,24 @@ module Timeout
return yield(sec) if sec == nil or sec.zero?
exception = klass || Class.new(ExitException)
begin
- x = Thread.current
- y = Thread.start {
- begin
- sleep sec
- rescue => e
- x.raise e
- else
- x.raise exception, "execution expired" if x.alive?
+ begin
+ x = Thread.current
+ y = Thread.start {
+ begin
+ sleep sec
+ rescue => e
+ x.raise e
+ else
+ x.raise exception, "execution expired"
+ end
+ }
+ return yield(sec)
+ ensure
+ if y
+ y.kill
+ y.join # make sure y is dead.
end
- }
- return yield(sec)
+ end
rescue exception => e
rej = /\A#{Regexp.quote(__FILE__)}:#{__LINE__-4}\z/o
(bt = e.backtrace).reject! {|m| rej =~ m}
@@ -66,11 +73,6 @@ module Timeout
raise if klass # if exception class is specified, it
# would be expected outside.
raise Error, e.message, e.backtrace
- ensure
- if y and y.alive?
- y.kill
- y.join # make sure y is dead.
- end
end
end