[前][次][番号順一覧][スレッド一覧]

ruby-changes:26198

From: nobu <ko1@a...>
Date: Fri, 7 Dec 2012 14:05:32 +0900 (JST)
Subject: [ruby-changes:26198] nobu:r38255 (trunk): timeout.rb: replace deferred exception after async_interrupt_timing

nobu	2012-12-07 14:04:02 +0900 (Fri, 07 Dec 2012)

  New Revision: 38255

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38255

  Log:
    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]

  Modified files:
    trunk/ChangeLog
    trunk/lib/timeout.rb
    trunk/test/test_timeout.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38254)
+++ ChangeLog	(revision 38255)
@@ -1,3 +1,9 @@
+Fri Dec  7 14:03:59 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@z...>
 
 	* doc/forwardable.rd: Remove stale documentation file
Index: lib/timeout.rb
===================================================================
--- lib/timeout.rb	(revision 38254)
+++ lib/timeout.rb	(revision 38255)
@@ -50,8 +50,8 @@
   def timeout(sec, klass = nil, immediate: false)   #:yield: +sec+
     return yield(sec) if sec == nil or sec.zero?
     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
           x = Thread.current
           y = Thread.start {
@@ -70,18 +70,18 @@
             y.join # make sure y is dead.
           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
+    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
 
Index: test/test_timeout.rb
===================================================================
--- test/test_timeout.rb	(revision 38254)
+++ test/test_timeout.rb	(revision 38255)
@@ -62,7 +62,8 @@
       }
       sleep 0.5
       t.raise RuntimeError
-      assert_raise(RuntimeError) {
+      assert_raise(Timeout::Error) {
+        # deferred interrupt should raise
         t.join
       }
     ensure

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]