[MacRuby] #176: timeout fails to raise a Timeout::Error

MacRuby ruby-noreply at macosforge.org
Fri Aug 20 02:52:53 PDT 2010


#176: timeout fails to raise a Timeout::Error
---------------------------------+------------------------------------------
 Reporter:  acangiano@…          |       Owner:  lsansonetti@…        
     Type:  defect               |      Status:  new                  
 Priority:  major                |   Milestone:                       
Component:  MacRuby              |    Keywords:                       
---------------------------------+------------------------------------------

Comment(by watson1978@…):

 I propose the following patch as a workaround until the problem of Thread
 is solved.

 Please give me an opinion :-)

 {{{
 #!diff
 diff --git a/lib/timeout.rb b/lib/timeout.rb
 index 297b769..a478720 100644
 --- a/lib/timeout.rb
 +++ b/lib/timeout.rb
 @@ -40,11 +40,13 @@ module Timeout
    # Note that this is both a method of module Timeout, so you can
 'include Timeout'
    # into your classes so they have a #timeout method, as well as a module
 method,
    # so you can call it directly as Timeout.timeout().
 -  def timeout(sec, klass = nil)   #:yield: +sec+
 +  def timeout(sec, klass = nil, &block)   #:yield: +sec+
      return yield(sec) if sec == nil or sec.zero?
      exception = klass || Class.new(ExitException)
      begin
 -      x = Thread.current
 +      x = Thread.start {
 +        block.call(sec)
 +      }
        y = Thread.start {
          begin
            sleep sec
 @@ -54,7 +56,8 @@ module Timeout
            x.raise exception, "execution expired" if x.alive?
          end
        }
 -      return yield(sec)
 +      x.join
 +      return sec
      rescue exception => e
        rej = /\A#{Regexp.quote(__FILE__)}:#{__LINE__-4}\z/o
        (bt = e.backtrace).reject! {|m| rej =~ m}
 }}}

-- 
Ticket URL: <http://www.macruby.org/trac/ticket/176#comment:2>
MacRuby <http://macruby.org/>



More information about the macruby-tickets mailing list