Class: Selenium::WebDriver::ChildProcess Private
- Inherits:
-
Object
- Object
- Selenium::WebDriver::ChildProcess
- Defined in:
- 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.
Defined Under Namespace
Classes: TimeoutError
Constant Summary collapse
- 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
- #detach ⇒ Object private
- #io ⇒ Object private
Class Method Summary collapse
- .build(*command) ⇒ Object private
Instance Method Summary collapse
- #alive? ⇒ Boolean private
- #exited? ⇒ Boolean private
-
#initialize(*command) ⇒ ChildProcess
constructor
private
A new instance of ChildProcess.
- #poll_for_exit(timeout) ⇒ Object private
- #start ⇒ Object private
- #stop(timeout = 3) ⇒ Object private
- #wait ⇒ Object private
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.
42 43 44 45 46 47 |
# File 'lib/selenium/webdriver/common/child_process.rb', line 42 def initialize(*command) @command = command @detach = false @pid = nil @status = nil end |
Instance Attribute Details
#detach ⇒ 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.
35 36 37 |
# File 'lib/selenium/webdriver/common/child_process.rb', line 35 def detach @detach end |
#io ⇒ 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.
49 50 51 |
# File 'lib/selenium/webdriver/common/child_process.rb', line 49 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.
38 39 40 |
# File 'lib/selenium/webdriver/common/child_process.rb', line 38 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.
74 75 76 |
# File 'lib/selenium/webdriver/common/child_process.rb', line 74 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.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/selenium/webdriver/common/child_process.rb', line 78 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 |
#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.
94 95 96 97 98 99 100 101 |
# File 'lib/selenium/webdriver/common/child_process.rb', line 94 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 ⇒ 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.
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/selenium/webdriver/common/child_process.rb', line 53 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 #{options}", id: :process) @pid = Process.spawn(*@command, ) 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.
64 65 66 67 68 69 70 71 72 |
# File 'lib/selenium/webdriver/common/child_process.rb', line 64 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 |
#wait ⇒ 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.
103 104 105 106 107 |
# File 'lib/selenium/webdriver/common/child_process.rb', line 103 def wait return if exited? _, @status = waitpid2(@pid) end |