Parent

Class/Module Index [+]

Quicksearch

Selenium::WebDriver::ChildProcess

Cross platform child process launcher

@private

Attributes

pid[R]

Public Class Methods

new(*args) click to toggle source
# File common/src/rb/lib/selenium/webdriver/child_process.rb, line 13
def initialize(*args)
  @args = args

  if Platform.jruby?
    extend JRubyProcess
  elsif Platform.ironruby?
    extend IronRubyProcess
  elsif Platform.os == :windows
    extend WindowsProcess
  end
end

Public Instance Methods

assert_started() click to toggle source
# File common/src/rb/lib/selenium/webdriver/child_process.rb, line 114
def assert_started
  raise Error::WebDriverError, "process not started" unless @pid
end
ensure_death() click to toggle source

Tries increasingly harsher methods to make the process die within a reasonable time

# File common/src/rb/lib/selenium/webdriver/child_process.rb, line 56
def ensure_death
  begin
    $stderr.puts "wait_nonblock(5) -> #{self}" if $DEBUG
    return wait_nonblock(5)
  rescue Error::TimeOutError
    # try next
  end

  $stderr.puts "TERM -> #{self}" if $DEBUG
  kill

  begin
    $stderr.puts "wait_nonblock(5) -> #{self}" if $DEBUG
    return wait_nonblock(5)
  rescue Error::TimeOutError
    # try next
  end

  $stderr.puts "KILL -> #{self}" if $DEBUG
  kill!

  $stderr.puts "wait_nonblock(5) -> #{self}" if $DEBUG
  wait_nonblock(5)
rescue Errno::ECHILD
  # great!
  true
end
exit_value() click to toggle source

Returns the exit value of the process, or nil if it’s still alive.

# File common/src/rb/lib/selenium/webdriver/child_process.rb, line 34
def exit_value
  pid, status = Process.waitpid2(@pid, Process::WNOHANG)
  status.exitstatus if pid
end
kill() click to toggle source
# File common/src/rb/lib/selenium/webdriver/child_process.rb, line 104
def kill
  assert_started
  Process.kill('TERM', @pid)
end
kill!() click to toggle source
# File common/src/rb/lib/selenium/webdriver/child_process.rb, line 109
def kill!
  assert_started
  Process.kill('KILL', @pid)
end
start() click to toggle source
# File common/src/rb/lib/selenium/webdriver/child_process.rb, line 39
def start
  @pid = fork do
    unless $DEBUG
      [STDOUT, STDERR].each { |io| io.reopen("/dev/null") }
    end

    exec(*@args)
  end

  self
end
ugly_death?() click to toggle source
# File common/src/rb/lib/selenium/webdriver/child_process.rb, line 25
def ugly_death?
  code = exit_value
  code && code != 0
end
wait() click to toggle source
# File common/src/rb/lib/selenium/webdriver/child_process.rb, line 97
def wait
  assert_started
  Process.waitpid2 @pid
rescue Errno::ECHILD
  nil
end
wait_nonblock(timeout) click to toggle source
# File common/src/rb/lib/selenium/webdriver/child_process.rb, line 84
def wait_nonblock(timeout)
  end_time = Time.now + timeout
  until Time.now > end_time || exited = exit_value
    sleep 0.1
  end

  unless exited
    raise Error::TimeOutError, "process still alive after #{timeout} seconds"
  end

  exited
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.