* 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/trunk@31623 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kosaki 2011-05-18 11:31:58 +00:00
Родитель 73bb32d4dd
Коммит da3d9e99dd
2 изменённых файлов: 22 добавлений и 15 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Wed May 18 20:25:04 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* lib/timeout.rb (Timeout#timeout): don't leak "execution expired"
exception. [Bug #4283] [ruby-core:34534].
Wed May 18 06:09:24 2011 Eric Hodel <drbrain@segment7.net> Wed May 18 06:09:24 2011 Eric Hodel <drbrain@segment7.net>
* lib/cmath.rb: Add some examples and improve documentation. Patch by * lib/cmath.rb: Add some examples and improve documentation. Patch by

Просмотреть файл

@ -46,17 +46,24 @@ module Timeout
return yield(sec) if sec == nil or sec.zero? return yield(sec) if sec == nil or sec.zero?
exception = klass || Class.new(ExitException) exception = klass || Class.new(ExitException)
begin begin
x = Thread.current begin
y = Thread.start { x = Thread.current
begin y = Thread.start {
sleep sec begin
rescue => e sleep sec
x.raise e rescue => e
else x.raise e
x.raise exception, "execution expired" if x.alive? else
x.raise exception, "execution expired"
end
}
return yield(sec)
ensure
if y
y.kill
y.join # make sure y is dead.
end end
} end
return yield(sec)
rescue exception => e rescue exception => e
rej = /\A#{Regexp.quote(__FILE__)}:#{__LINE__-4}\z/o rej = /\A#{Regexp.quote(__FILE__)}:#{__LINE__-4}\z/o
(bt = e.backtrace).reject! {|m| rej =~ m} (bt = e.backtrace).reject! {|m| rej =~ m}
@ -68,11 +75,6 @@ module Timeout
raise if klass # if exception class is specified, it raise if klass # if exception class is specified, it
# would be expected outside. # would be expected outside.
raise Error, e.message, e.backtrace raise Error, e.message, e.backtrace
ensure
if y and y.alive?
y.kill
y.join # make sure y is dead.
end
end end
end end