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
Constant Summary
- POLL_INTERVAL =
0.1
Instance Attribute Summary (collapse)
-
- (Object) detach
Set this to true if you do not care about when or if the process quits.
-
- (Object) duplex
Set this to true if you want to write to the process' stdin (process.io.stdin).
-
- (Object) exit_code
readonly
Returns the value of attribute exit_code.
Instance Method Summary (collapse)
-
- (Boolean) alive?
Is this process running?.
-
- (Boolean) crashed?
Returns true if the process has exited and the exit code was not 0.
-
- (Boolean) exited?
Did the process exit?.
-
- (AbstractProcess) initialize(args)
constructor
private
Create a new process with the given args.
-
- (Object) io
Returns a ChildProcess::AbstractIO subclass to configure the child's IO streams.
- - (Object) pid
-
- (Object) poll_for_exit(timeout)
Wait for the process to exit, raising a ChildProcess::TimeoutError if the timeout expires.
-
- (AbstractProcess) start
Launch the child process.
-
- (Object) stop(timeout = 3)
Forcibly terminate the process, using increasingly harsher methods if possible.
Constructor Details
- (AbstractProcess) initialize(args)
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.
24 25 26 27 28 29 30 |
# File 'lib/childprocess/abstract_process.rb', line 24 def initialize(args) @args = args @started = false @exit_code = nil @detach = false @duplex = false end |
Instance Attribute Details
- (Object) detach
Set this to true if you do not care about when or if the process quits.
10 11 12 |
# File 'lib/childprocess/abstract_process.rb', line 10 def detach @detach end |
- (Object) duplex
Set this to true if you want to write to the process' stdin (process.io.stdin)
15 16 17 |
# File 'lib/childprocess/abstract_process.rb', line 15 def duplex @duplex end |
- (Object) exit_code (readonly)
Returns the value of attribute exit_code
5 6 7 |
# File 'lib/childprocess/abstract_process.rb', line 5 def exit_code @exit_code end |
Instance Method Details
- (Boolean) alive?
Is this process running?
83 84 85 |
# File 'lib/childprocess/abstract_process.rb', line 83 def alive? started? && !exited? end |
- (Boolean) crashed?
Returns true if the process has exited and the exit code was not 0.
93 94 95 |
# File 'lib/childprocess/abstract_process.rb', line 93 def crashed? exited? && @exit_code != 0 end |
- (Boolean) exited?
Did the process exit?
73 74 75 |
# File 'lib/childprocess/abstract_process.rb', line 73 def exited? raise SubclassResponsibility, "exited?" end |
- (Object) io
Returns a ChildProcess::AbstractIO subclass to configure the child's IO streams.
36 37 38 |
# File 'lib/childprocess/abstract_process.rb', line 36 def io raise SubclassResponsibility, "io" end |
- (Object) pid
40 41 42 |
# File 'lib/childprocess/abstract_process.rb', line 40 def pid raise SubclassResponsibility, "pid" end |
- (Object) poll_for_exit(timeout)
Wait for the process to exit, raising a ChildProcess::TimeoutError if the timeout expires.
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/childprocess/abstract_process.rb', line 102 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 |
- (AbstractProcess) start
Launch the child process
50 51 52 53 54 55 |
# File 'lib/childprocess/abstract_process.rb', line 50 def start launch_process @started = true self end |
- (Object) stop(timeout = 3)
Forcibly terminate the process, using increasingly harsher methods if possible.
63 64 65 |
# File 'lib/childprocess/abstract_process.rb', line 63 def stop(timeout = 3) raise SubclassResponsibility, "stop" end |