Class: ASIR::Application::Spawn
- Inherits:
-
Object
- Object
- ASIR::Application::Spawn
- Defined in:
- lib/asir/application.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#blk ⇒ Object
Returns the value of attribute blk.
-
#cmd ⇒ Object
Returns the value of attribute cmd.
-
#name ⇒ Object
Returns the value of attribute name.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#tmp ⇒ Object
Returns the value of attribute tmp.
-
#tmp_out ⇒ Object
Returns the value of attribute tmp_out.
Instance Method Summary collapse
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
23 24 25 |
# File 'lib/asir/application.rb', line 23 def app @app end |
#blk ⇒ Object
Returns the value of attribute blk.
23 24 25 |
# File 'lib/asir/application.rb', line 23 def blk @blk end |
#cmd ⇒ Object
Returns the value of attribute cmd.
23 24 25 |
# File 'lib/asir/application.rb', line 23 def cmd @cmd end |
#name ⇒ Object
Returns the value of attribute name.
23 24 25 |
# File 'lib/asir/application.rb', line 23 def name @name end |
#pid ⇒ Object
Returns the value of attribute pid.
23 24 25 |
# File 'lib/asir/application.rb', line 23 def pid @pid end |
#tmp ⇒ Object
Returns the value of attribute tmp.
23 24 25 |
# File 'lib/asir/application.rb', line 23 def tmp @tmp end |
#tmp_out ⇒ Object
Returns the value of attribute tmp_out.
23 24 25 |
# File 'lib/asir/application.rb', line 23 def tmp_out @tmp_out end |
Instance Method Details
#go! ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/asir/application.rb', line 30 def go! case RUBY_PLATFORM when /java/i @tmp = "/tmp/#{$$}.#{name}" @tmp_out = "#{tmp}.out" @tmp_run = "#{tmp}.run" File.unlink(@tmp_out) rescue nil File.unlink(@tmp_run) rescue nil begin require 'spoon' ruby = ASIR.ruby_path # ruby = "/usr/bin/ruby" inc = app.inc.map{|x| "-I#{x}"} @cmd = [ ruby ] @cmd.concat(inc) @cmd.concat([ $0, "--asir-spawn=#{name}", @tmp ]) $stderr.puts "#{self} cmd #{cmd * ' '}" if verbose @pid = Spoon.spawnp(*cmd) # Wait until started. until File.exist?(@tmp_run) sleep 0.1 end ensure File.unlink(@tmp_run) rescue nil end else @pid = Process.fork(&blk) end @pid end |
#kill ⇒ Object
61 62 63 64 |
# File 'lib/asir/application.rb', line 61 def kill Process.kill 9, pid wait end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/asir/application.rb', line 26 def to_s "#<#{self.class.name} #{name.inspect} #{@pid} >" end |
#verbose ⇒ Object
24 |
# File 'lib/asir/application.rb', line 24 def verbose; app.verbose; end |
#wait ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/asir/application.rb', line 66 def wait # Wait until finished and collect output. begin Process.waitpid(pid) while true Process.kill(0, pid) sleep 1 end rescue Errno::ECHILD, Errno::ESRCH ensure $stderr.puts "Spawn #{self} finished" if verbose @pid = nil if tmp_out && File.exist?(tmp_out) $stdout.write(File.read(tmp_out)) File.unlink(tmp_out) end @tmp_out = nil end end |