execute 0.1.64 → 0.1.65

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 +13 -5
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f292e7da56b9d559da658d511a6d2bec12657938
4
- data.tar.gz: 045a2bccfc873bb5a0a9e433f50863959dd37ff6
3
+ metadata.gz: c9c3a10cf310529427b81e4f7fd174bab6f275bf
4
+ data.tar.gz: abf191c993c3e3162762cc5bbd60bff655119ab5
5
5
  SHA512:
6
- metadata.gz: ff0c210b446a4faf9a55b23a1a8a0cf4b9e8b558312057d30153e26dfb64b517b22f8fa7b746d79797d70afff35d701fb4af2e589e36b77c2d9b4f1b529759c1
7
- data.tar.gz: 1cb83faf1d62dc10901fd2f304d8f95aa8d089d67f45ff919d7e5cc66e0b7215808ffccd8f5686c0b667f5e3971625738975c0c837f8e9af2064c4e041db3141
6
+ metadata.gz: a7a90bc3626c1b270ebc0c53e529317fc80f2f42a8d7482f944f502d4ff05437208eefed956467afdeea283fea0eadc1198e686b84416ef82cba7a55783ba4fb
7
+ data.tar.gz: 43e211fd4a782099c3d8e93f21df795d5921bde6127ea85f27af3e1ad99881648d8cb6b26ad009716173e99c4f111ba40df61d0cd8b37c3bd7cf2c4478ffe1c4
@@ -73,17 +73,22 @@ class Execute < Hash
73
73
  begin
74
74
  output = ''
75
75
  error = ''
76
+
76
77
  mutex = Mutex.new
78
+ stop_threads = false
79
+ timeout = nil
80
+ timeout = self[:timeout] if(key?(:timeout))
77
81
 
78
82
  Open3.popen3(self[:command]) do |stdin, stdout, stderr, wait_thr|
79
83
  self[:pid] = wait_thr.pid
80
84
 
81
- if(key?(:timeout))
85
+ unless(timeout.nil?)
82
86
  start_time = Time.now
83
87
  Thread.new do
84
- while wait_thr.alive? do
85
- if((Time.now - start_time).to_f > self[:timeout])
86
- self[:timed_out] = true
88
+ while wait_thr.alive? && !stop_threads do
89
+ if((Time.now - start_time).to_f > timeout)
90
+ mutex.synchronize { self[:timed_out] = true }
91
+ mutex.synchronize { stop_threads = true }
87
92
  interrupt
88
93
  Thread.stop
89
94
  end
@@ -95,10 +100,11 @@ class Execute < Hash
95
100
  {:output => stdout,:error => stderr}.each do |key, stream|
96
101
  Thread.new do
97
102
  begin
98
- while wait_thr.alive? && !key?(:timed_out) && !@stop_threads do
103
+ while wait_thr.alive? && !stop_threads do
99
104
  unless(stream.closed?)
100
105
  if((char = stream.getc).nil?)
101
106
  sleep(0.1)
107
+ thread.pass
102
108
  else
103
109
  case key
104
110
  when :output
@@ -110,7 +116,9 @@ class Execute < Hash
110
116
  end
111
117
  end
112
118
  end
119
+ mutex.synchronize { stop_threads = true }
113
120
  rescue IOError
121
+ mutex.synchronize { stop_threads = true }
114
122
  Thread.stop
115
123
  end
116
124
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: execute
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.64
4
+ version: 0.1.65
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Marshall