kommando 0.0.17 → 0.0.18

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: 9003ef03825d24dbed6e95661acc172cae3509a7
4
- data.tar.gz: abc099820ae559c3c69554c632e8a81e3c0b017b
3
+ metadata.gz: 114c6d5e9933de3694419b769250a48d36f92c70
4
+ data.tar.gz: 50f77767dd71d6b195d72af7d3e4d2bd727a2e3f
5
5
  SHA512:
6
- metadata.gz: 004d3ec64ecee487262b169b10421ec753965d96db4580e837d090ea8678bf0fe39d40f15ad876fd5e0076e11f36fecb66f6b3e02deba12dc8c49c82e300a768
7
- data.tar.gz: 6f81c0dff25c9e21bfd0ddb15f14575c630936ce4d5e42c2c942660f5dc3e9b4e818832ebee7c66b40be10d85450aca4afab4a0db51523482d9dbc08e92f3e6a
6
+ metadata.gz: 4529a5e5c95b7fca83e13a2c1fe77dd5b5a0f5842171af8b0c3c1f1b15acfacc9dbe3e11406622b1e025e3143a5d407fc3e74ceb0bd4ca39f6edcdece7a06474
7
+ data.tar.gz: 362e3369d281e2ccfb222abcf51a781d057bbe5981a55601b00ee1287786957d3215b9c7b396e2d51f1e2f21835adc498ffdefcede597373754b61cb4269371f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.0.18
4
+ Fixes thread leak and some hangs.
5
+
6
+ - FIX: Fixes hang when reading stdout.
7
+ - FIX: Thread leak.
8
+
3
9
  ## 0.0.17
4
10
  Fixes race condition and reduces the number of threads Kommando creates.
5
11
 
@@ -0,0 +1,10 @@
1
+ require "./lib/kommando"
2
+
3
+ 100.times do
4
+ k = Kommando.run "uptime"
5
+ print "."
6
+ end
7
+ sleep 0.25
8
+
9
+ raise "Thread leak" unless Thread.list.count == 1
10
+ puts "ok"
data/lib/kommando.rb CHANGED
@@ -52,6 +52,7 @@ class Kommando
52
52
 
53
53
  @code = nil
54
54
  @executed = false
55
+ @process_completed = false
55
56
 
56
57
  if opts[:retry]
57
58
  if opts[:retry][:times]
@@ -155,7 +156,12 @@ class Kommando
155
156
  thread_stdin = Thread.new do
156
157
  sleep 0.1 # allow program to start, do not write "in terminal"
157
158
  while true do
159
+ break if @process_completed
160
+ # c = nil
161
+ # Timeout.timeout(1) do
158
162
  c = @stdin.getc
163
+ #end
164
+
159
165
  unless c
160
166
  sleep 0.01
161
167
  next
@@ -170,15 +176,16 @@ class Kommando
170
176
  if @timeout
171
177
  begin
172
178
  Timeout.timeout(@timeout) do
173
- process_stdout(stdout, stdout_file)
179
+ process_stdout(pid, stdout, stdout_file)
174
180
  end
175
181
  rescue Timeout::Error
176
182
  Process.kill('KILL', pid)
177
183
  @timeout_happened = true
178
184
  end
179
185
  else
180
- process_stdout(stdout, stdout_file)
186
+ process_stdout(pid, stdout, stdout_file)
181
187
  end
188
+ @process_completed = true
182
189
 
183
190
  stdout_file.close if @output_file
184
191
  end
@@ -279,17 +286,17 @@ class Kommando
279
286
  PTY
280
287
  end
281
288
 
282
- def process_stdout(stdout, stdout_file)
289
+ def process_stdout(pid, stdout, stdout_file)
290
+ flushing = false
283
291
  while true do
284
292
  begin
285
- break if stdout.eof?
286
- rescue Errno::EIO
287
- # Linux http://stackoverflow.com/a/7263243
288
- break
293
+ Process.getpgid(pid)
294
+ rescue Errno::ESRCH => ex
295
+ flushing = true
289
296
  end
290
297
 
291
298
  c = stdout.getc
292
-
299
+ break if flushing == true && c == nil
293
300
  next unless c
294
301
 
295
302
  @stdout.append c if c
@@ -1,3 +1,3 @@
1
1
  class Kommando
2
- VERSION = "0.0.17"
2
+ VERSION = "0.0.18"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kommando
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matti Paksula
@@ -132,6 +132,7 @@ files:
132
132
  - examples/shorthands.rb
133
133
  - examples/stderr_to_out.rb
134
134
  - examples/stdout_to_file.rb
135
+ - examples/thread_leak.rb
135
136
  - examples/timeout.rb
136
137
  - examples/uptime.rb
137
138
  - examples/wait.rb