Sha256: 20f65c0e570c829dd74a11ae3f2c2ee59cf574a4b9b86ac9b92554e1e470468d

Contents?: true

Size: 1.77 KB

Versions: 5

Compression:

Stored size: 1.77 KB

Contents

require 'drb'
require 'skynet/guid_generator'
require 'skynet/logger'
require 'skynet/config'
require 'timeout'    

Skynet::CONFIG[:SKYNET_PATH] ||= File.expand_path(File.dirname(__FILE__) +"/..")

require 'skynet/debugger'
require 'skynet/message'
require 'skynet/message_queue_adapters/message_queue_adapter'
require 'skynet/message_queue_adapters/tuple_space'
require "skynet/message_queue"
require 'skynet/partitioners'
require 'skynet/job'
require 'skynet/worker'
require 'skynet/task'
require 'skynet/manager'
require 'skynet/tuplespace_server'
require 'skynet/ruby_extensions'
require 'skynet/mapreduce_test'
require 'skynet/launcher'
require 'skynet/console'
require 'skynet/mapreduce_helper'

begin
  require 'fastthread'
rescue LoadError
  # puts 'fastthread not installed, using thread instead'
  require 'thread'
end

class << Skynet

  # kinda like system() but gives me back a pid
  def fork_and_exec(command)
    sleep 0.01  # remove contention on manager drb object
    log = Skynet::Logger.get
    debug "executing /bin/sh -c \"#{command}\""
    pid = safefork do
      close_files
      exec("/bin/sh -c \"#{command}\"")
      exit
    end
    Process.detach(pid)
    pid
  end

  def safefork (&block)
    @fork_tries ||= 0
    fork(&block)
  rescue Errno::EWOULDBLOCK
    raise if @fork_tries >= 20
    @fork_tries += 1
    sleep 5
    retry
  end

  # close open file descriptors starting with STDERR+1
  def close_files(from=3, to=50)
    close_console
    (from .. to).each do |fd|
      IO.for_fd(fd).close rescue nil
     end
  end

  def close_console
    STDIN.reopen "/dev/null"
    STDOUT.reopen "/dev/null", "a"
    STDERR.reopen STDOUT 
  end

  def process_alive?(worker_pid)
    Process.kill(0,worker_pid)
    return true
  rescue Errno::ESRCH => e
    return false
  end  

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
brendan-skynet-0.9.303 lib/skynet.rb
brendan-skynet-0.9.304 lib/skynet.rb
brendan-skynet-0.9.305 lib/skynet.rb
brendan-skynet-0.9.310 lib/skynet.rb
brendan-skynet-0.9.311 lib/skynet.rb