shexecutor 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 183cea7f0c0edbb50faed8dd83fb9f520de34188
4
- data.tar.gz: 0c233c7824237a02ac9780dd7f787f32678d08a4
3
+ metadata.gz: d9b5ff685f5736caeee4b7da6f4ffdc89df35f6f
4
+ data.tar.gz: 1adec7351ce61aab38684cd7eb42f61ca9f3c0a7
5
5
  SHA512:
6
- metadata.gz: e9c31b3dc06489d8a93ec677eddd73a4225578ea32ecb0ecb5bb5b835095d18cb45e21d9ff0586af40d4d68464d856113600eff221f13108ffade8f9f0648576
7
- data.tar.gz: 2835e4e2ae9dd50b0acf12d3e0550dcae0188cf90a1a78c712849dc4f1e354992d58a3ca4d4e61227e7c4c22e29664ebaaf2b7a2248ff772c921214c645af4f2
6
+ metadata.gz: 211b5d32097888858bf38f4dba7344cc7bc4b1cd08edd2c6d183d797ef6af7869a5685ecb0723e75b8f7fd19027afcd207e709ef585c4abcba282a85a064d06f
7
+ data.tar.gz: 1021ef30c0a794c7f73ce021c8361057b843e3f53f44a14cff90900c7348f41776d3f877ed3779b4f6a4063916cf2a6ad44d529ddc6034849f148f11803db449
@@ -1,3 +1,3 @@
1
1
  module SHExecutor
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
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 srderr and stdout into buffers to prevent blocking
161
+ # read stderr and stdout into buffers to prevent blocking
162
162
  t1 = Thread.new do
163
- IO.copy_stream(stdout, data_out)
163
+ begin
164
+ IO.copy_stream(stdout, data_out)
165
+ end
164
166
  end
165
167
  t2 = Thread.new do
166
- IO.copy_stream(stderr, data_err)
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
- #These streams should never produce IOErrors. If they do, memory is shot.
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
- Timeout.timeout(@options[:timeout]) do
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shexecutor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernst van Graan