execute 0.1.66 → 0.1.67

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/execute.rb +28 -16
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66b5a207b61a6135c7a2450956c36096e17163c4
4
- data.tar.gz: 29686a56d20aa7aa76fc857fe24b665d4cce78d4
3
+ metadata.gz: f400a72ed951d57586f00ead9719775c1306c0ad
4
+ data.tar.gz: 4a0b12e141723950038c9b096987ec21bfa3b3a3
5
5
  SHA512:
6
- metadata.gz: fb8f9de4b7b364034f9895692aa31adaf5ef55ca1a63ca45c93b70a84419af298b3549ccfe7b47525648abad1068c9abf265a15fef72165c9eadf7710a0a624b
7
- data.tar.gz: cc3319e16988b19701e605d8ab649d921f80ee3e737106be947e1910a773b8a431750fce680e8cf090091be563821e537078a6b559b671ec9d1d02dc04807681
6
+ metadata.gz: f4bdb4436e67cf1a4129018dd5ded58bd1f6c8580e9e05a3c88d73b056c436db6074dcba294ac501cc9ceffd1770a30f01aa262482f1f18f1d8a01b6cb0549cf
7
+ data.tar.gz: 5f2bad414bce3ccd732c8144083ea5cd2a9c2b71280915189204d13f1ade0e8bc0d3455060daa8b4de43aca34f7cf864bd6fa4473ec92a52adebb739c85b6a9e
@@ -74,6 +74,7 @@ class Execute < Hash
74
74
  output = ''
75
75
  error = ''
76
76
 
77
+ threads = []
77
78
  mutex = Mutex.new
78
79
  stop_threads = false
79
80
  timeout = nil
@@ -84,27 +85,37 @@ class Execute < Hash
84
85
 
85
86
  unless(timeout.nil?)
86
87
  start_time = Time.now
87
- Thread.new do
88
- while wait_thr.alive? && !stop_threads do
89
- if((Time.now - start_time).to_f > timeout)
90
- self[:timed_out] = true
91
- mutex.synchronize { stop_threads = true }
92
- interrupt
93
- Thread.stop
88
+ end_loop = stop_threads
89
+ threads << Thread.new do
90
+ begin
91
+ while wait_thr.alive? && !end_loop do
92
+ if((Time.now - start_time).to_f > timeout)
93
+ self[:timed_out] = true
94
+ mutex.synchronize { stop_threads = true }
95
+ interrupt
96
+ Thread.exit
97
+ else
98
+ sleep(1)
99
+ Thread.pass
100
+ end
101
+ mutex.synchronize { end_loop = stop_threads }
94
102
  end
95
- sleep(1)
103
+ rescue Exception => e
104
+ mutex.synchronize { stop_threads = true }
105
+ Thread.exit
96
106
  end
97
107
  end
98
108
  end
99
109
 
100
110
  {:output => stdout,:error => stderr}.each do |key, stream|
101
- Thread.new do
111
+ threads << Thread.new do
102
112
  begin
103
- while wait_thr.alive? && !stop_threads do
113
+ end_loop = stop_threads
114
+ while wait_thr.alive? && !end_loop do
104
115
  unless(stream.closed?)
105
116
  if((char = stream.getc).nil?)
106
117
  sleep(0.1)
107
- thread.pass
118
+ Thread.pass
108
119
  else
109
120
  case key
110
121
  when :output
@@ -115,24 +126,25 @@ class Execute < Hash
115
126
  end
116
127
  end
117
128
  end
129
+ mutex.synchronize { end_loop = stop_threads }
118
130
  end
119
131
  mutex.synchronize { stop_threads = true }
120
- rescue IOError
132
+ rescue Exception
121
133
  mutex.synchronize { stop_threads = true }
122
- Thread.stop
134
+ Thread.exit
123
135
  end
124
136
  end
125
137
  end
126
138
 
127
- wait_thr.join
128
-
139
+ threads.each { |thr| thr.join }
140
+
129
141
  self[:output] = output unless(output.empty?)
130
142
  self[:error] = error unless(error.empty?)
131
143
  self[:exit_code] = wait_thr.value.to_i
132
144
  end
133
145
  rescue Exception => e
134
146
  self[:error] = "#{self[:error]}\nException: #{e.to_s}"
135
- self[:exit_code]=1 unless(self[:exit_code].nil? || (self[:exit_code] == 0))
147
+ self[:exit_code]=1 unless(self[:exit_code].nil? || (self[:exit_code] == 0))
136
148
  end
137
149
  end
138
150
  def call_capture
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: execute
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.66
4
+ version: 0.1.67
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Marshall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-27 00:00:00.000000000 Z
11
+ date: 2016-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler