Class: Selenium::WebDriver::ChildProcess
- Inherits:
-
Object
- Object
- Selenium::WebDriver::ChildProcess
show all
- Defined in:
- lib/selenium/webdriver/child_process.rb
Overview
Cross platform child process launcher
Defined Under Namespace
Modules: IronRubyProcess, JRubyProcess, WindowsProcess
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ChildProcess.
Instance Attribute Details
#pid ⇒ Object
Returns the value of attribute pid.
11
12
13
|
# File 'lib/selenium/webdriver/child_process.rb', line 11
def pid
@pid
end
|
Instance Method Details
#assert_started ⇒ Object
114
115
116
|
# File 'lib/selenium/webdriver/child_process.rb', line 114
def assert_started
raise Error::WebDriverError, "process not started" unless @pid
end
|
#ensure_death ⇒ Object
Tries increasingly harsher methods to make the process die within a reasonable time
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File '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
end
$stderr.puts "TERM -> #{self}" if $DEBUG
kill
begin
$stderr.puts "wait_nonblock(5) -> #{self}" if $DEBUG
return wait_nonblock(5)
rescue Error::TimeOutError
end
$stderr.puts "KILL -> #{self}" if $DEBUG
kill!
$stderr.puts "wait_nonblock(5) -> #{self}" if $DEBUG
wait_nonblock(5)
rescue Errno::ECHILD
true
end
|
#exit_value ⇒ Object
Returns the exit value of the process, or nil if it’s still alive.
34
35
36
37
|
# File 'lib/selenium/webdriver/child_process.rb', line 34
def exit_value
pid, status = Process.waitpid2(@pid, Process::WNOHANG)
status.exitstatus if pid
end
|
#kill ⇒ Object
104
105
106
107
|
# File 'lib/selenium/webdriver/child_process.rb', line 104
def kill
assert_started
Process.kill('TERM', @pid)
end
|
#kill! ⇒ Object
109
110
111
112
|
# File 'lib/selenium/webdriver/child_process.rb', line 109
def kill!
assert_started
Process.kill('KILL', @pid)
end
|
#start ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
|
# File '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? ⇒ Boolean
25
26
27
28
|
# File 'lib/selenium/webdriver/child_process.rb', line 25
def ugly_death?
code = exit_value
code && code != 0
end
|
#wait ⇒ Object
97
98
99
100
101
102
|
# File 'lib/selenium/webdriver/child_process.rb', line 97
def wait
assert_started
Process.waitpid2 @pid
rescue Errno::ECHILD
nil
end
|
#wait_nonblock(timeout) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
|
# File '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
|