shexecutor 0.0.12 → 0.0.13
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.
- checksums.yaml +4 -4
- data/lib/shexecutor/version.rb +1 -1
- data/lib/shexecutor.rb +22 -16
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9b5ff685f5736caeee4b7da6f4ffdc89df35f6f
|
4
|
+
data.tar.gz: 1adec7351ce61aab38684cd7eb42f61ca9f3c0a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 211b5d32097888858bf38f4dba7344cc7bc4b1cd08edd2c6d183d797ef6af7869a5685ecb0723e75b8f7fd19027afcd207e709ef585c4abcba282a85a064d06f
|
7
|
+
data.tar.gz: 1021ef30c0a794c7f73ce021c8361057b843e3f53f44a14cff90900c7348f41776d3f877ed3779b4f6a4063916cf2a6ad44d529ddc6034849f148f11803db449
|
data/lib/shexecutor/version.rb
CHANGED
data/lib/shexecutor.rb
CHANGED
@@ -158,24 +158,30 @@ module SHExecutor
|
|
158
158
|
@t0 = nil
|
159
159
|
Open3::popen3(application_path, options) do |stdin, stdout, stderr, thr|
|
160
160
|
@t0 = thr
|
161
|
-
# read
|
161
|
+
# read stderr and stdout into buffers to prevent blocking
|
162
162
|
t1 = Thread.new do
|
163
|
-
|
163
|
+
begin
|
164
|
+
IO.copy_stream(stdout, data_out)
|
165
|
+
end
|
164
166
|
end
|
165
167
|
t2 = Thread.new do
|
166
|
-
|
168
|
+
begin
|
169
|
+
IO.copy_stream(stderr, data_err)
|
170
|
+
end
|
167
171
|
end
|
172
|
+
# track timeout if required. Do this ourselves since the mechanism
|
173
|
+
# is simple and Timeout struggles from multi-threading issues.
|
174
|
+
# IO.copy_stream stop the Timeout exception from being thrown properly.
|
175
|
+
t3 = Thread.new do
|
176
|
+
count = 0
|
177
|
+
while (count < @options[:timeout]*10) and (@t0.alive?) do
|
178
|
+
sleep 0.1
|
179
|
+
count = count + 1
|
180
|
+
end
|
181
|
+
raise Timeout::Error.new("execution expired") if @t0.alive?
|
182
|
+
end if should_timeout?
|
168
183
|
stdin.close
|
169
|
-
|
170
|
-
#Having them abort on exception interrupts TimeoutError, so turn abort of
|
171
|
-
#wanting to see timeouts
|
172
|
-
t1.abort_on_exception = false if should_timeout?
|
173
|
-
t2.abort_on_exception = false if should_timeout?
|
174
|
-
#No need to join here. t0 is joined by the caller.
|
175
|
-
#Explicitly join here if not configured for timeout to make the point that
|
176
|
-
#if you join here when configured for timeout, timeout will break, as the
|
177
|
-
#join will only finish when the thread finishes, i.e. the timeout exception
|
178
|
-
#will come too late
|
184
|
+
t3.abort_on_exception = true if should_timeout?
|
179
185
|
t1.join if not should_timeout?
|
180
186
|
t2.join if not should_timeout?
|
181
187
|
end
|
@@ -192,9 +198,7 @@ module SHExecutor
|
|
192
198
|
def block_process_with_timeout
|
193
199
|
validate
|
194
200
|
begin
|
195
|
-
|
196
|
-
@data_out, @data_err, @result = run_process(@options[:application_path], *@options[:params])
|
197
|
-
end
|
201
|
+
@data_out, @data_err, @result = run_process(@options[:application_path], *@options[:params])
|
198
202
|
@result.join
|
199
203
|
@result.value
|
200
204
|
rescue Timeout::Error => ex
|
@@ -220,6 +224,8 @@ module SHExecutor
|
|
220
224
|
sleep 0.1
|
221
225
|
end
|
222
226
|
Process.kill(9, pid) if process?(pid)
|
227
|
+
rescue Errno::ESRCH
|
228
|
+
#done
|
223
229
|
end
|
224
230
|
|
225
231
|
def fork_process
|