Class: ChildProcess::AbstractProcess
- Inherits:
-
Object
- Object
- ChildProcess::AbstractProcess
- Defined in:
- lib/childprocess/abstract_process.rb
Direct Known Subclasses
IronRuby::Process, JRuby::Process, Unix::Process, Windows::Process
Instance Attribute Summary collapse
-
#exit_code ⇒ Object
readonly
Returns the value of attribute exit_code.
Instance Method Summary collapse
-
#alive? ⇒ Boolean
Is this process running?.
- #crashed? ⇒ Boolean
-
#exited? ⇒ Boolean
Did the process exit?.
-
#initialize(args) ⇒ AbstractProcess
constructor
A new instance of AbstractProcess.
- #poll_for_exit(timeout) ⇒ Object
-
#start ⇒ AbstractProcess
Launch the child process.
-
#stop(timeout = 3) ⇒ Object
Forcibly terminate the process, using increasingly harsher methods if possible.
Constructor Details
#initialize(args) ⇒ AbstractProcess
Returns a new instance of AbstractProcess.
5 6 7 8 9 |
# File 'lib/childprocess/abstract_process.rb', line 5 def initialize(args) @args = args @started = false @exit_code = nil end |
Instance Attribute Details
#exit_code ⇒ Object (readonly)
Returns the value of attribute exit_code.
3 4 5 |
# File 'lib/childprocess/abstract_process.rb', line 3 def exit_code @exit_code end |
Instance Method Details
#alive? ⇒ Boolean
Is this process running?
48 49 50 |
# File 'lib/childprocess/abstract_process.rb', line 48 def alive? started? && !exited? end |
#crashed? ⇒ Boolean
52 53 54 |
# File 'lib/childprocess/abstract_process.rb', line 52 def crashed? @exit_code && @exit_code != 0 end |
#exited? ⇒ Boolean
Did the process exit?
40 41 42 |
# File 'lib/childprocess/abstract_process.rb', line 40 def exited? raise SubclassResponsibility, "exited?" end |
#poll_for_exit(timeout) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/childprocess/abstract_process.rb', line 56 def poll_for_exit(timeout) log "polling #{timeout} seconds for exit" end_time = Time.now + timeout until (ok = exited?) || Time.now > end_time sleep POLL_INTERVAL end unless ok raise TimeoutError, "process still alive after #{timeout} seconds" end end |
#start ⇒ AbstractProcess
Launch the child process
17 18 19 20 21 22 |
# File 'lib/childprocess/abstract_process.rb', line 17 def start launch_process @started = true self end |
#stop(timeout = 3) ⇒ Object
Forcibly terminate the process, using increasingly harsher methods if possible.
30 31 32 |
# File 'lib/childprocess/abstract_process.rb', line 30 def stop(timeout = 3) raise SubclassResponsibility, "stop" end |