childprocess 0.5.9 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.document +6 -6
  3. data/.gitignore +25 -25
  4. data/.rspec +1 -1
  5. data/.travis.yml +20 -18
  6. data/CHANGELOG.md +8 -0
  7. data/Gemfile +11 -4
  8. data/LICENSE +20 -20
  9. data/README.md +178 -178
  10. data/Rakefile +61 -61
  11. data/childprocess.gemspec +30 -29
  12. data/lib/childprocess.rb +184 -177
  13. data/lib/childprocess/abstract_io.rb +36 -36
  14. data/lib/childprocess/abstract_process.rb +187 -187
  15. data/lib/childprocess/errors.rb +26 -26
  16. data/lib/childprocess/jruby.rb +56 -56
  17. data/lib/childprocess/jruby/io.rb +16 -16
  18. data/lib/childprocess/jruby/process.rb +159 -159
  19. data/lib/childprocess/jruby/pump.rb +52 -52
  20. data/lib/childprocess/tools/generator.rb +145 -145
  21. data/lib/childprocess/unix.rb +9 -9
  22. data/lib/childprocess/unix/fork_exec_process.rb +70 -70
  23. data/lib/childprocess/unix/io.rb +21 -21
  24. data/lib/childprocess/unix/lib.rb +186 -186
  25. data/lib/childprocess/unix/platform/i386-linux.rb +12 -12
  26. data/lib/childprocess/unix/platform/i386-solaris.rb +11 -11
  27. data/lib/childprocess/unix/platform/x86_64-linux.rb +12 -12
  28. data/lib/childprocess/unix/platform/x86_64-macosx.rb +11 -11
  29. data/lib/childprocess/unix/posix_spawn_process.rb +134 -134
  30. data/lib/childprocess/unix/process.rb +89 -89
  31. data/lib/childprocess/version.rb +3 -3
  32. data/lib/childprocess/windows.rb +33 -33
  33. data/lib/childprocess/windows/handle.rb +91 -91
  34. data/lib/childprocess/windows/io.rb +25 -25
  35. data/lib/childprocess/windows/lib.rb +415 -415
  36. data/lib/childprocess/windows/process.rb +129 -129
  37. data/lib/childprocess/windows/process_builder.rb +174 -174
  38. data/lib/childprocess/windows/structs.rb +148 -148
  39. data/spec/abstract_io_spec.rb +12 -12
  40. data/spec/childprocess_spec.rb +291 -256
  41. data/spec/io_spec.rb +228 -228
  42. data/spec/jruby_spec.rb +24 -24
  43. data/spec/pid_behavior.rb +12 -12
  44. data/spec/spec_helper.rb +253 -253
  45. data/spec/unix_spec.rb +57 -57
  46. data/spec/windows_spec.rb +23 -23
  47. metadata +47 -45
@@ -1,36 +1,36 @@
1
- module ChildProcess
2
- class AbstractIO
3
- attr_reader :stderr, :stdout, :stdin
4
-
5
- def inherit!
6
- @stdout = STDOUT
7
- @stderr = STDERR
8
- end
9
-
10
- def stderr=(io)
11
- check_type io
12
- @stderr = io
13
- end
14
-
15
- def stdout=(io)
16
- check_type io
17
- @stdout = io
18
- end
19
-
20
- #
21
- # @api private
22
- #
23
-
24
- def _stdin=(io)
25
- check_type io
26
- @stdin = io
27
- end
28
-
29
- private
30
-
31
- def check_type(io)
32
- raise SubclassResponsibility, "check_type"
33
- end
34
-
35
- end
36
- end
1
+ module ChildProcess
2
+ class AbstractIO
3
+ attr_reader :stderr, :stdout, :stdin
4
+
5
+ def inherit!
6
+ @stdout = STDOUT
7
+ @stderr = STDERR
8
+ end
9
+
10
+ def stderr=(io)
11
+ check_type io
12
+ @stderr = io
13
+ end
14
+
15
+ def stdout=(io)
16
+ check_type io
17
+ @stdout = io
18
+ end
19
+
20
+ #
21
+ # @api private
22
+ #
23
+
24
+ def _stdin=(io)
25
+ check_type io
26
+ @stdin = io
27
+ end
28
+
29
+ private
30
+
31
+ def check_type(io)
32
+ raise SubclassResponsibility, "check_type"
33
+ end
34
+
35
+ end
36
+ end
@@ -1,187 +1,187 @@
1
- module ChildProcess
2
- class AbstractProcess
3
- POLL_INTERVAL = 0.1
4
-
5
- attr_reader :exit_code
6
-
7
- #
8
- # Set this to true if you do not care about when or if the process quits.
9
- #
10
- attr_accessor :detach
11
-
12
- #
13
- # Set this to true if you want to write to the process' stdin (process.io.stdin)
14
- #
15
- attr_accessor :duplex
16
-
17
- #
18
- # Modify the child's environment variables
19
- #
20
- attr_reader :environment
21
-
22
- #
23
- # Set the child's current working directory.
24
- #
25
- attr_accessor :cwd
26
-
27
- #
28
- #
29
- # Set this to true to make the child process the leader of a new process group
30
- #
31
- # This can be used to make sure that all grandchildren are killed
32
- # when the child process dies.
33
- #
34
- attr_accessor :leader
35
-
36
- #
37
- # Create a new process with the given args.
38
- #
39
- # @api private
40
- # @see ChildProcess.build
41
- #
42
-
43
- def initialize(args)
44
- unless args.all? { |e| e.kind_of?(String) }
45
- raise ArgumentError, "all arguments must be String: #{args.inspect}"
46
- end
47
-
48
- @args = args
49
- @started = false
50
- @exit_code = nil
51
- @io = nil
52
- @cwd = nil
53
- @detach = false
54
- @duplex = false
55
- @leader = false
56
- @environment = {}
57
- end
58
-
59
- #
60
- # Returns a ChildProcess::AbstractIO subclass to configure the child's IO streams.
61
- #
62
-
63
- def io
64
- raise SubclassResponsibility, "io"
65
- end
66
-
67
- #
68
- # @return [Fixnum] the pid of the process after it has started
69
- #
70
-
71
- def pid
72
- raise SubclassResponsibility, "pid"
73
- end
74
-
75
- #
76
- # Launch the child process
77
- #
78
- # @return [AbstractProcess] self
79
- #
80
-
81
- def start
82
- launch_process
83
- @started = true
84
-
85
- self
86
- end
87
-
88
- #
89
- # Forcibly terminate the process, using increasingly harsher methods if possible.
90
- #
91
- # @param [Fixnum] timeout (3) Seconds to wait before trying the next method.
92
- #
93
-
94
- def stop(timeout = 3)
95
- raise SubclassResponsibility, "stop"
96
- end
97
-
98
- #
99
- # Block until the process has been terminated.
100
- #
101
- # @return [Fixnum] The exit status of the process
102
- #
103
-
104
- def wait
105
- raise SubclassResponsibility, "wait"
106
- end
107
-
108
- #
109
- # Did the process exit?
110
- #
111
- # @return [Boolean]
112
- #
113
-
114
- def exited?
115
- raise SubclassResponsibility, "exited?"
116
- end
117
-
118
- #
119
- # Is this process running?
120
- #
121
- # @return [Boolean]
122
- #
123
-
124
- def alive?
125
- started? && !exited?
126
- end
127
-
128
- #
129
- # Returns true if the process has exited and the exit code was not 0.
130
- #
131
- # @return [Boolean]
132
- #
133
-
134
- def crashed?
135
- exited? && @exit_code != 0
136
- end
137
-
138
- #
139
- # Wait for the process to exit, raising a ChildProcess::TimeoutError if
140
- # the timeout expires.
141
- #
142
-
143
- def poll_for_exit(timeout)
144
- log "polling #{timeout} seconds for exit"
145
-
146
- end_time = Time.now + timeout
147
- until (ok = exited?) || Time.now > end_time
148
- sleep POLL_INTERVAL
149
- end
150
-
151
- unless ok
152
- raise TimeoutError, "process still alive after #{timeout} seconds"
153
- end
154
- end
155
-
156
- private
157
-
158
- def launch_process
159
- raise SubclassResponsibility, "launch_process"
160
- end
161
-
162
- def started?
163
- @started
164
- end
165
-
166
- def detach?
167
- @detach
168
- end
169
-
170
- def duplex?
171
- @duplex
172
- end
173
-
174
- def leader?
175
- @leader
176
- end
177
-
178
- def log(*args)
179
- $stderr.puts "#{self.inspect} : #{args.inspect}" if $DEBUG
180
- end
181
-
182
- def assert_started
183
- raise Error, "process not started" unless started?
184
- end
185
-
186
- end # AbstractProcess
187
- end # ChildProcess
1
+ module ChildProcess
2
+ class AbstractProcess
3
+ POLL_INTERVAL = 0.1
4
+
5
+ attr_reader :exit_code
6
+
7
+ #
8
+ # Set this to true if you do not care about when or if the process quits.
9
+ #
10
+ attr_accessor :detach
11
+
12
+ #
13
+ # Set this to true if you want to write to the process' stdin (process.io.stdin)
14
+ #
15
+ attr_accessor :duplex
16
+
17
+ #
18
+ # Modify the child's environment variables
19
+ #
20
+ attr_reader :environment
21
+
22
+ #
23
+ # Set the child's current working directory.
24
+ #
25
+ attr_accessor :cwd
26
+
27
+ #
28
+ #
29
+ # Set this to true to make the child process the leader of a new process group
30
+ #
31
+ # This can be used to make sure that all grandchildren are killed
32
+ # when the child process dies.
33
+ #
34
+ attr_accessor :leader
35
+
36
+ #
37
+ # Create a new process with the given args.
38
+ #
39
+ # @api private
40
+ # @see ChildProcess.build
41
+ #
42
+
43
+ def initialize(args)
44
+ unless args.all? { |e| e.kind_of?(String) }
45
+ raise ArgumentError, "all arguments must be String: #{args.inspect}"
46
+ end
47
+
48
+ @args = args
49
+ @started = false
50
+ @exit_code = nil
51
+ @io = nil
52
+ @cwd = nil
53
+ @detach = false
54
+ @duplex = false
55
+ @leader = false
56
+ @environment = {}
57
+ end
58
+
59
+ #
60
+ # Returns a ChildProcess::AbstractIO subclass to configure the child's IO streams.
61
+ #
62
+
63
+ def io
64
+ raise SubclassResponsibility, "io"
65
+ end
66
+
67
+ #
68
+ # @return [Integer] the pid of the process after it has started
69
+ #
70
+
71
+ def pid
72
+ raise SubclassResponsibility, "pid"
73
+ end
74
+
75
+ #
76
+ # Launch the child process
77
+ #
78
+ # @return [AbstractProcess] self
79
+ #
80
+
81
+ def start
82
+ launch_process
83
+ @started = true
84
+
85
+ self
86
+ end
87
+
88
+ #
89
+ # Forcibly terminate the process, using increasingly harsher methods if possible.
90
+ #
91
+ # @param [Integer] timeout (3) Seconds to wait before trying the next method.
92
+ #
93
+
94
+ def stop(timeout = 3)
95
+ raise SubclassResponsibility, "stop"
96
+ end
97
+
98
+ #
99
+ # Block until the process has been terminated.
100
+ #
101
+ # @return [Integer] The exit status of the process
102
+ #
103
+
104
+ def wait
105
+ raise SubclassResponsibility, "wait"
106
+ end
107
+
108
+ #
109
+ # Did the process exit?
110
+ #
111
+ # @return [Boolean]
112
+ #
113
+
114
+ def exited?
115
+ raise SubclassResponsibility, "exited?"
116
+ end
117
+
118
+ #
119
+ # Is this process running?
120
+ #
121
+ # @return [Boolean]
122
+ #
123
+
124
+ def alive?
125
+ started? && !exited?
126
+ end
127
+
128
+ #
129
+ # Returns true if the process has exited and the exit code was not 0.
130
+ #
131
+ # @return [Boolean]
132
+ #
133
+
134
+ def crashed?
135
+ exited? && @exit_code != 0
136
+ end
137
+
138
+ #
139
+ # Wait for the process to exit, raising a ChildProcess::TimeoutError if
140
+ # the timeout expires.
141
+ #
142
+
143
+ def poll_for_exit(timeout)
144
+ log "polling #{timeout} seconds for exit"
145
+
146
+ end_time = Time.now + timeout
147
+ until (ok = exited?) || Time.now > end_time
148
+ sleep POLL_INTERVAL
149
+ end
150
+
151
+ unless ok
152
+ raise TimeoutError, "process still alive after #{timeout} seconds"
153
+ end
154
+ end
155
+
156
+ private
157
+
158
+ def launch_process
159
+ raise SubclassResponsibility, "launch_process"
160
+ end
161
+
162
+ def started?
163
+ @started
164
+ end
165
+
166
+ def detach?
167
+ @detach
168
+ end
169
+
170
+ def duplex?
171
+ @duplex
172
+ end
173
+
174
+ def leader?
175
+ @leader
176
+ end
177
+
178
+ def log(*args)
179
+ $stderr.puts "#{self.inspect} : #{args.inspect}" if $DEBUG
180
+ end
181
+
182
+ def assert_started
183
+ raise Error, "process not started" unless started?
184
+ end
185
+
186
+ end # AbstractProcess
187
+ end # ChildProcess
@@ -1,26 +1,26 @@
1
- module ChildProcess
2
- class Error < StandardError
3
- end
4
-
5
- class TimeoutError < Error
6
- end
7
-
8
- class SubclassResponsibility < Error
9
- end
10
-
11
- class InvalidEnvironmentVariable < Error
12
- end
13
-
14
- class LaunchError < Error
15
- end
16
-
17
- class MissingPlatformError < Error
18
- def initialize
19
- message = "posix_spawn is not yet supported on #{ChildProcess.platform_name} (#{RUBY_PLATFORM}), falling back to default implementation. " +
20
- "If you believe this is an error, please file a bug at http://github.com/jarib/childprocess/issues"
21
-
22
- super(message)
23
- end
24
-
25
- end
26
- end
1
+ module ChildProcess
2
+ class Error < StandardError
3
+ end
4
+
5
+ class TimeoutError < Error
6
+ end
7
+
8
+ class SubclassResponsibility < Error
9
+ end
10
+
11
+ class InvalidEnvironmentVariable < Error
12
+ end
13
+
14
+ class LaunchError < Error
15
+ end
16
+
17
+ class MissingPlatformError < Error
18
+ def initialize
19
+ message = "posix_spawn is not yet supported on #{ChildProcess.platform_name} (#{RUBY_PLATFORM}), falling back to default implementation. " +
20
+ "If you believe this is an error, please file a bug at http://github.com/enkessler/childprocess/issues"
21
+
22
+ super(message)
23
+ end
24
+
25
+ end
26
+ end