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
-
#detach ⇒ Object
Set this to true if you do not care about when or if the process quits.
-
#exit_code ⇒ Object
readonly
Returns the value of attribute exit_code.
Instance Method Summary collapse
-
#alive? ⇒ Boolean
Is this process running?.
-
#crashed? ⇒ Boolean
Returns true if the process has exited and the exit code was not 0.
-
#exited? ⇒ Boolean
Did the process exit?.
-
#initialize(args) ⇒ AbstractProcess
constructor
private
Create a new process with the given args.
-
#io ⇒ Object
Returns a ChildProcess::AbstractIO subclass to configure the child’s IO streams.
-
#poll_for_exit(timeout) ⇒ Object
Wait for the process to exit, raising a ChildProcess::TimeoutError if the timeout expires.
-
#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
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.
Create a new process with the given args.
18 19 20 21 22 23 |
# File 'lib/childprocess/abstract_process.rb', line 18 def initialize(args) @args = args @started = false @exit_code = nil @detach = false end |
Instance Attribute Details
#detach ⇒ Object
Set this to true if you do not care about when or if the process quits.
8 9 10 |
# File 'lib/childprocess/abstract_process.rb', line 8 def detach @detach end |
#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?
72 73 74 |
# File 'lib/childprocess/abstract_process.rb', line 72 def alive? started? && !exited? end |
#crashed? ⇒ Boolean
Returns true if the process has exited and the exit code was not 0.
82 83 84 |
# File 'lib/childprocess/abstract_process.rb', line 82 def crashed? exited? && @exit_code != 0 end |
#exited? ⇒ Boolean
Did the process exit?
62 63 64 |
# File 'lib/childprocess/abstract_process.rb', line 62 def exited? raise SubclassResponsibility, "exited?" end |
#io ⇒ Object
Returns a ChildProcess::AbstractIO subclass to configure the child’s IO streams.
29 30 31 |
# File 'lib/childprocess/abstract_process.rb', line 29 def io raise SubclassResponsibility, "io" end |
#poll_for_exit(timeout) ⇒ Object
Wait for the process to exit, raising a ChildProcess::TimeoutError if the timeout expires.
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/childprocess/abstract_process.rb', line 91 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
39 40 41 42 43 44 |
# File 'lib/childprocess/abstract_process.rb', line 39 def start launch_process @started = true self end |
#stop(timeout = 3) ⇒ Object
Forcibly terminate the process, using increasingly harsher methods if possible.
52 53 54 |
# File 'lib/childprocess/abstract_process.rb', line 52 def stop(timeout = 3) raise SubclassResponsibility, "stop" end |