lib/webby/stelan/spawner.rb
# call-seq:
#    _spawn    => thread
#
# Creates a thread that will spawn the sub-process via
# <code>IO::popen</code>. If the sub-process terminates, it will be
# respawned until the +stop+ message is sent to this spawner.
#
# If an Exception is encountered during the spawning process, a message
# will be printed to stderr and the thread will exit.
#
call-seq:
_spawn    => thread

Creates a thread that will spawn the sub-process via
IO::popen. If the sub-process terminates, it will be
respawned until the +stop+ message is sent to this spawner.

If an Exception is encountered during the spawning process, a message
will be printed to stderr and the thread will exit.
call - seq : _spawn = > thread Creates a thread that will spawn the sub - process via IO :: popen . If the sub - process terminates it will be respawned until the + stop + message is sent to this spawner . If an Exception is encountered during the spawning process a message will be printed to stderr and the thread will exit .
def _spawn
    t = Thread.new do
          catch(:die) do
            loop do
              begin
                io = IO.popen("#{@ruby} #{@tmp.path}", 'r')
                cid = io.gets.to_i
                @cids.sync {@cids << cid} if cid > 0
                Process.wait cid
              rescue Exception => e
                STDERR.puts e.inspect
                STDERR.puts e.backtrace.join("\n")
                throw :die
              ensure
                io.close rescue nil
                @cids.sync {
                  @cids.delete cid
                  throw :die unless @cids.length < @spawn
                }
              end
              throw :die if @stop
              sleep @pause
            end  
          end  
        end  
    @group.add t
    t
  end
def _spawn t = Thread . new do catch ( :die ) do loop do begin io = IO . popen ( "#{@ruby} #{@tmp.path}" , 'r' ) cid = io . gets . to_i @cids . sync { @cids << cid } if cid > 0 Process . wait cid rescue Exception => e STDERR . puts e . inspect STDERR . puts e . backtrace . join ( "\n" ) throw :die ensure io . close rescue nil @cids . sync { @cids . delete cid throw :die unless @cids . length < @spawn } end throw :die if @stop sleep @pause end end end @group . add t t end
call-seq:
_spawn    => thread
call - seq : _spawn = > thread
# loop # catch(:die) # Thread.new