Class: Selenium::WebDriver::ChildProcess Private

Inherits:
Object
  • Object
show all
Defined in:
rb/lib/selenium/webdriver/common/child_process.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

TimeoutError =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Class.new(StandardError)
SIGTERM =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'TERM'
SIGKILL =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'KILL'
POLL_INTERVAL =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

0.1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*command) ⇒ ChildProcess

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ChildProcess.



41
42
43
44
45
46
# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 41

def initialize(*command)
  @command = command
  @detach = false
  @pid = nil
  @status = nil
end

Instance Attribute Details

#detachObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 34

def detach
  @detach
end

#ioObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 48

def io
  @io ||= Platform.null_device
end

Class Method Details

.build(*command) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



37
38
39
# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 37

def self.build(*command)
  new(*command)
end

Instance Method Details

#alive?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


79
80
81
# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 79

def alive?
  @pid && !exited?
end

#exited?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


83
84
85
86
87
88
89
90
91
92
93
94
# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 83

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
end

#poll_for_exit(timeout) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:



96
97
98
99
100
101
102
103
# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 96

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

#startObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



52
53
54
55
56
57
58
59
60
61
# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 52

def start
  options = {%i[out err] => io}
  options[:pgroup] = true unless Platform.windows? # NOTE: this is a bug only in Windows 7

  WebDriver.logger.debug("Starting process: #{@command} with #{options}", id: :process)
  @pid = Process.spawn(*@command, options)
  WebDriver.logger.debug("  -> pid: #{@pid}", id: :process)

  Process.detach(@pid) if detach
end

#stop(timeout = 3) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 63

def stop(timeout = 3)
  return unless @pid
  return if exited?

  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

#waitObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



105
106
107
108
109
# File 'rb/lib/selenium/webdriver/common/child_process.rb', line 105

def wait
  return if exited?

  _, @status = waitpid2(@pid)
end