summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-19 03:46:17 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-19 03:46:17 +0000
commit23f9ffbf35f79fcfb57dddb8331440d857a46b22 (patch)
tree7c2b3bcfde0b2ff20fcb628317d8b3e86d524f3c /lib
parent505def84d4beeb4be60f75b905b3cd3e2e0a39a1 (diff)
* lib/timeout.rb (Timeout#timeout): propagate errors to the
caller. [ruby-dev:41010]' git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@27395 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/timeout.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/timeout.rb b/lib/timeout.rb
index 5a99c28092..e60b4e3f13 100644
--- a/lib/timeout.rb
+++ b/lib/timeout.rb
@@ -56,8 +56,13 @@ module Timeout
begin
x = Thread.current
y = Thread.start {
- sleep sec
- x.raise exception, "execution expired" if x.alive?
+ begin
+ sleep sec
+ rescue => e
+ x.raise e
+ else
+ x.raise exception, "execution expired" if x.alive?
+ end
}
yield sec
# return true
@@ -73,7 +78,10 @@ module Timeout
# would be expected outside.
raise Error, e.message, e.backtrace
ensure
- y.kill if y and y.alive?
+ if y and y.alive?
+ y.kill
+ y.join # make sure y is dead.
+ end
end
end