shexecutor 0.0.15 → 0.0.16

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b5339cd977bce2d3fc0afd8e1e91a0acca62226
4
- data.tar.gz: 8480574bea646115896463bfea7bebd317d08462
3
+ metadata.gz: f5a90086a0b0551fc5c8296e15e8261a6c05103e
4
+ data.tar.gz: b471206bf6fe04e173ca72e5690eace7e922233f
5
5
  SHA512:
6
- metadata.gz: 5bcf1d372db5a9be80f1e226116bb5d62f56c0562d4a1e5c1e2ae1845896e669edf46451abeca9a510ffb37d8c2cad3b6879f6f34eff4eebd1cc7ccb767015cc
7
- data.tar.gz: f03082a03fa5972324e69912f64f80e8eb73290bf317071958c0be7063f5b865de3bd4de2d4bd371ee44594ac7f90e86add35fb7bb299c3c73e2d1c935814a95
6
+ metadata.gz: e7eaf4861a28bac3294e80ab2745261693f3cadba1f84b07ed78337c4c325f728ea0c94196d99725b857c3d9debbdc31fe5c89cc569bb798642863331c05fb73
7
+ data.tar.gz: e62998f6d86fb8ae0200cf880b7c4dc29e6a3dc4ee62dc4147e4cae09709e1b68f0c2a318dd268ea4b290e42b7a803e1f042107c94e491358afcd39696ed7489
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shexecutor (0.0.14)
4
+ shexecutor (0.0.15)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,3 +1,3 @@
1
1
  module SHExecutor
2
- VERSION = "0.0.15"
2
+ VERSION = "0.0.16"
3
3
  end
data/lib/shexecutor.rb CHANGED
@@ -162,11 +162,15 @@ module SHExecutor
162
162
  t1 = Thread.new do
163
163
  begin
164
164
  IO.copy_stream(stdout, data_out)
165
+ rescue Exception => ex
166
+ raise TimeoutError.new("execution expired") if @timeout_error
165
167
  end
166
168
  end
167
169
  t2 = Thread.new do
168
170
  begin
169
171
  IO.copy_stream(stderr, data_err)
172
+ rescue Exception => ex
173
+ raise TimeoutError.new("execution expired") if @timeout_error
170
174
  end
171
175
  end
172
176
  m = Mutex.new
@@ -174,6 +178,7 @@ module SHExecutor
174
178
  # track timeout if required. Do this ourselves since the mechanism
175
179
  # is simple and Timeout struggles from multi-threading issues.
176
180
  # IO.copy_stream stop the Timeout exception from being thrown properly.
181
+ timedout = false
177
182
  t3 = Thread.new do
178
183
  count = 0
179
184
  while (count < @options[:timeout]*10) and (@t0.alive?) do
@@ -181,11 +186,15 @@ module SHExecutor
181
186
  count = count + 1
182
187
  end
183
188
  m.synchronize do
189
+ if count >= @options[:timeout]*10
190
+ timedout = true
191
+ end
184
192
  done = true
185
- raise Timeout::Error.new("execution expired") if @t0.alive?
186
193
  end
187
194
  end if should_timeout?
188
195
  stdin.close
196
+ t1.abort_on_exception = true if should_timeout?
197
+ t2.abort_on_exception = true if should_timeout?
189
198
  t3.abort_on_exception = true if should_timeout?
190
199
  t1.join if not should_timeout?
191
200
  t2.join if not should_timeout?
@@ -200,9 +209,14 @@ module SHExecutor
200
209
  d = done
201
210
  end
202
211
  end
203
- t1.join if not @t0.alive?
204
- t2.join if not @t0.alive?
205
- t3.join if not @t0.alive?
212
+
213
+ if not timedout
214
+ t1.join
215
+ t2.join
216
+ t3.join
217
+ else
218
+ @timeout_error = true
219
+ end
206
220
  end
207
221
  end
208
222
  return data_out, data_err, @t0
@@ -219,6 +233,7 @@ module SHExecutor
219
233
  validate
220
234
  begin
221
235
  @data_out, @data_err, @result = run_process(@options[:application_path], *@options[:params])
236
+ raise Timeout::Error.new("execution expired") if @timeout_error
222
237
  @result.join
223
238
  @result.value
224
239
  rescue Timeout::Error => ex
@@ -236,6 +251,13 @@ module SHExecutor
236
251
  end
237
252
  end
238
253
 
254
+ def kill_9_process(pid)
255
+ return if pid.nil?
256
+ Process.kill(9, pid)
257
+ rescue Errno::ESRCH
258
+ #done
259
+ end
260
+
239
261
  def kill_process(pid)
240
262
  return if pid.nil?
241
263
  Process.kill("TERM", pid)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shexecutor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernst van Graan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-25 00:00:00.000000000 Z
11
+ date: 2015-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler