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
This commit is contained in:
parent
9dd64b6053
commit
08f0db2c68
@ -1,3 +1,9 @@
|
|||||||
|
Fri Dec 7 14:03:59 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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]
|
||||||
|
|
||||||
Fri Dec 7 13:07:00 2012 Zachary Scott <zachary@zacharyscott.net>
|
Fri Dec 7 13:07:00 2012 Zachary Scott <zachary@zacharyscott.net>
|
||||||
|
|
||||||
* doc/forwardable.rd: Remove stale documentation file
|
* doc/forwardable.rd: Remove stale documentation file
|
||||||
|
@ -50,8 +50,8 @@ module Timeout
|
|||||||
def timeout(sec, klass = nil, immediate: false) #:yield: +sec+
|
def timeout(sec, klass = nil, immediate: false) #:yield: +sec+
|
||||||
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)
|
||||||
Thread.async_interrupt_timing(exception => immediate ? :immediate : :on_blocking) do
|
begin
|
||||||
begin
|
Thread.async_interrupt_timing(exception => immediate ? :immediate : :on_blocking) do
|
||||||
begin
|
begin
|
||||||
x = Thread.current
|
x = Thread.current
|
||||||
y = Thread.start {
|
y = Thread.start {
|
||||||
@ -70,18 +70,18 @@ module Timeout
|
|||||||
y.join # make sure y is dead.
|
y.join # make sure y is dead.
|
||||||
end
|
end
|
||||||
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
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -62,7 +62,8 @@ class TestTimeout < Test::Unit::TestCase
|
|||||||
}
|
}
|
||||||
sleep 0.5
|
sleep 0.5
|
||||||
t.raise RuntimeError
|
t.raise RuntimeError
|
||||||
assert_raise(RuntimeError) {
|
assert_raise(Timeout::Error) {
|
||||||
|
# deferred interrupt should raise
|
||||||
t.join
|
t.join
|
||||||
}
|
}
|
||||||
ensure
|
ensure
|
||||||
|
Loading…
x
Reference in New Issue
Block a user