Class: Selenium::WebDriver::ChildProcess Private
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | rb/lib/selenium/webdriver/common/child_process.rb |
Constant Summary
-
POLL_INTERVAL =
# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 320.1
-
SIGKILL =
# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 30'KILL'
-
SIGTERM =
# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 29'TERM'
-
TimeoutError =
# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 27Class.new(StandardError)
Class Method Summary
- .build(*command) Internal use only
- .new(*command) ⇒ ChildProcess constructor Internal use only
Instance Attribute Summary
- #alive? ⇒ Boolean readonly Internal use only
- #detach rw Internal use only
- #exited? ⇒ Boolean readonly Internal use only
- #io rw Internal use only
- #io=(value) rw Internal use only
Instance Method Summary
- #poll_for_exit(timeout) Internal use only
- #start Internal use only
- #stop(timeout = 3) Internal use only
- #wait Internal use only
- #kill(pid) private Internal use only
- #terminate(pid) private Internal use only
- #terminate_and_wait_else_kill(timeout) private Internal use only
- #waitpid2(pid, flags = 0) private Internal use only
Constructor Details
.new(*command) ⇒ ChildProcess
# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 41
def initialize(*command) @command = command @detach = false @pid = nil @status = nil end
Class Method Details
.build(*command)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 37
def self.build(*command) new(*command) end
Instance Attribute Details
#alive? ⇒ Boolean
(readonly)
# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 73
def alive? @pid && !exited? end
#detach (rw)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 34
attr_accessor :detach
#exited? ⇒ Boolean
(readonly)
# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 77
def exited? return false unless @pid WebDriver.logger.debug("Checking if #{@pid} is exited:", id: :process) _, @status = waitpid2(@pid, Process::WNOHANG | Process::WUNTRACED) if @status.nil? return false if @status.nil? exit_code = @status.exitstatus || @status.termsig WebDriver.logger.debug(" -> exit code is #{exit_code.inspect}", id: :process) !!exit_code rescue Errno::ECHILD, Errno::ESRCH WebDriver.logger.debug(" -> process: #{@pid} already finished", id: :process) true end
#io (rw)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 48
def io @io ||= Platform.null_device end
#io=(value) (rw)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 35
attr_writer :io
Instance Method Details
#kill(pid) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 127
def kill(pid) Process.kill(SIGKILL, pid) end
#poll_for_exit(timeout)
# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 93
def poll_for_exit(timeout) WebDriver.logger.debug("Polling #{timeout} seconds for exit of #{@pid}", id: :process) end_time = Time.now + timeout sleep POLL_INTERVAL until exited? || Time.now > end_time raise TimeoutError, " -> #{@pid} still alive after #{timeout} seconds" unless exited? end
#start
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 52
def start = {%i[out err] => io} [:pgroup] = true unless Platform.windows? # NOTE: this is a bug only in Windows 7 WebDriver.logger.debug("Starting process: #{@command} with #{}", id: :process) @pid = Process.spawn(*@command, ) WebDriver.logger.debug(" -> pid: #{@pid}", id: :process) Process.detach(@pid) if detach end
#stop(timeout = 3)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 63
def stop(timeout = 3) return unless @pid return if exited? terminate_and_wait_else_kill(timeout) rescue Errno::ECHILD, Errno::ESRCH => e # Process exited earlier than terminate/kill could catch WebDriver.logger.debug(" -> process: #{@pid} does not exist (#{e.class.name})", id: :process) end
#terminate(pid) (private)
[ GitHub ]#terminate_and_wait_else_kill(timeout) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 110
def terminate_and_wait_else_kill(timeout) WebDriver.logger.debug("Sending TERM to process: #{@pid}", id: :process) terminate(@pid) poll_for_exit(timeout) WebDriver.logger.debug(" -> stopped #{@pid}", id: :process) rescue TimeoutError, Errno::EINVAL WebDriver.logger.debug(" -> sending KILL to process: #{@pid}", id: :process) kill(@pid) wait WebDriver.logger.debug(" -> killed #{@pid}", id: :process) end
#wait
[ GitHub ]#waitpid2(pid, flags = 0) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 131
def waitpid2(pid, flags = 0) Process.waitpid2(pid, flags) end