mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Revert r38216 and r38221. Release manager mark this feature as "next minor".
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38260 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
65129f3a5d
commit
3bbffbc7dd
4 changed files with 18 additions and 106 deletions
17
ChangeLog
17
ChangeLog
|
@ -208,23 +208,6 @@ Thu Dec 6 01:10:36 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
called, as mentioned in r14173. patched by charliesome (Charlie
|
called, as mentioned in r14173. patched by charliesome (Charlie
|
||||||
Somerville). [ruby-core:50489] [Bug #7499]
|
Somerville). [ruby-core:50489] [Bug #7499]
|
||||||
|
|
||||||
Thu Dec 6 00:51:21 2012 Masaya Tarui <tarui@ruby-lang.org>
|
|
||||||
|
|
||||||
* lib/timeout.rb (Timeout#timeout): specify a exception
|
|
||||||
more strictly at async_interrupt_timing.
|
|
||||||
|
|
||||||
Wed Dec 5 04:50:17 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
|
||||||
|
|
||||||
* lib/timeout.rb (Timeout#timeout): set
|
|
||||||
async_interrupt_timing(:on_blocking) by default.
|
|
||||||
[Bug #7503] [ruby-core:50524]
|
|
||||||
|
|
||||||
* test/test_timeout.rb (test_timeout_blocking): test for the above.
|
|
||||||
* test/test_timeout.rb (test_timeout_immediate): ditto
|
|
||||||
* test/test_timeout.rb (test_timeout_immediate2): ditto.
|
|
||||||
|
|
||||||
* NEWS: news for the above.
|
|
||||||
|
|
||||||
Wed Dec 5 23:50:23 2012 Narihiro Nakamura <authornari@gmail.com>
|
Wed Dec 5 23:50:23 2012 Narihiro Nakamura <authornari@gmail.com>
|
||||||
|
|
||||||
* gc.c (getrusage_time): uses clock_gettime() with
|
* gc.c (getrusage_time): uses clock_gettime() with
|
||||||
|
|
7
NEWS
7
NEWS
|
@ -332,13 +332,6 @@ with all sufficient information, see the ChangeLog file.
|
||||||
are introduced for easy detection of available constants on a
|
are introduced for easy detection of available constants on a
|
||||||
running system.
|
running system.
|
||||||
|
|
||||||
* timeout
|
|
||||||
* Timeout.timeout supports immediate optional keyword parameter.
|
|
||||||
* incompatible changes:
|
|
||||||
* Timeout.timeout now use async_interrupt_timing(:on_blocking) by default.
|
|
||||||
And then, timeout is only happen on blocking point (e.g. sleep, read,
|
|
||||||
write, Mutex#lock and so on).
|
|
||||||
|
|
||||||
* tmpdir
|
* tmpdir
|
||||||
* incompatible changes:
|
* incompatible changes:
|
||||||
* Dir.mktmpdir uses FileUtils.remove_entry instead of
|
* Dir.mktmpdir uses FileUtils.remove_entry instead of
|
||||||
|
|
|
@ -47,28 +47,26 @@ module Timeout
|
||||||
# Note that this is both a method of module Timeout, so you can <tt>include
|
# Note that this is both a method of module Timeout, so you can <tt>include
|
||||||
# Timeout</tt> into your classes so they have a #timeout method, as well as
|
# Timeout</tt> into your classes so they have a #timeout method, as well as
|
||||||
# a module method, so you can call it directly as Timeout.timeout().
|
# a module method, so you can call it directly as Timeout.timeout().
|
||||||
def timeout(sec, klass = nil, immediate: false) #:yield: +sec+
|
def timeout(sec, klass = nil) #: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)
|
||||||
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 {
|
begin
|
||||||
begin
|
sleep sec
|
||||||
sleep sec
|
rescue => e
|
||||||
rescue => e
|
x.raise e
|
||||||
x.raise e
|
else
|
||||||
else
|
x.raise exception, "execution expired"
|
||||||
x.raise exception, "execution expired"
|
|
||||||
end
|
|
||||||
}
|
|
||||||
return yield(sec)
|
|
||||||
ensure
|
|
||||||
if y
|
|
||||||
y.kill
|
|
||||||
y.join # make sure y is dead.
|
|
||||||
end
|
end
|
||||||
|
}
|
||||||
|
return yield(sec)
|
||||||
|
ensure
|
||||||
|
if y
|
||||||
|
y.kill
|
||||||
|
y.join # make sure y is dead.
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue exception => e
|
rescue exception => e
|
||||||
|
@ -80,7 +78,7 @@ module Timeout
|
||||||
level += 1
|
level += 1
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,7 +18,7 @@ class TestTimeout < Test::Unit::TestCase
|
||||||
}
|
}
|
||||||
assert_nothing_raised("[ruby-dev:38319]") do
|
assert_nothing_raised("[ruby-dev:38319]") do
|
||||||
Timeout.timeout(1) {
|
Timeout.timeout(1) {
|
||||||
sleep 0.01 while @flag
|
nil while @flag
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
assert !@flag, "[ruby-dev:38319]"
|
assert !@flag, "[ruby-dev:38319]"
|
||||||
|
@ -29,66 +29,4 @@ class TestTimeout < Test::Unit::TestCase
|
||||||
def (n = Object.new).zero?; false; end
|
def (n = Object.new).zero?; false; end
|
||||||
assert_raise(TypeError, bug3168) {Timeout.timeout(n) { sleep 0.1 }}
|
assert_raise(TypeError, bug3168) {Timeout.timeout(n) { sleep 0.1 }}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_timeout_immediate
|
|
||||||
begin
|
|
||||||
t = Thread.new {
|
|
||||||
Timeout.timeout(0.1, immediate: true) {
|
|
||||||
# loop forever, but can be interrupted
|
|
||||||
loop {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sleep 0.5
|
|
||||||
t.raise RuntimeError
|
|
||||||
assert_raise(Timeout::Error) {
|
|
||||||
t.join
|
|
||||||
}
|
|
||||||
ensure
|
|
||||||
t.kill if t.alive?
|
|
||||||
begin
|
|
||||||
t.join
|
|
||||||
rescue Exception
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_timeout_immediate2
|
|
||||||
begin
|
|
||||||
t = Thread.new {
|
|
||||||
Timeout.timeout(0.1) {
|
|
||||||
# loop forever, must not interrupted
|
|
||||||
loop {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sleep 0.5
|
|
||||||
t.raise RuntimeError
|
|
||||||
assert_raise(Timeout::Error) {
|
|
||||||
# deferred interrupt should raise
|
|
||||||
t.join
|
|
||||||
}
|
|
||||||
ensure
|
|
||||||
t.kill if t.alive?
|
|
||||||
begin
|
|
||||||
t.join
|
|
||||||
rescue Exception
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_timeout_blocking
|
|
||||||
t0 = Time.now
|
|
||||||
begin
|
|
||||||
Timeout.timeout(0.1) {
|
|
||||||
while true do
|
|
||||||
t1 = Time.now
|
|
||||||
break if t1 - t0 > 1
|
|
||||||
end
|
|
||||||
sleep 2
|
|
||||||
}
|
|
||||||
rescue Timeout::Error
|
|
||||||
end
|
|
||||||
t1 = Time.now
|
|
||||||
assert (t1 - t0) >= 1
|
|
||||||
assert (t1 - t0) < 2
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue