execute 0.1.64 → 0.1.65
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/execute.rb +13 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9c3a10cf310529427b81e4f7fd174bab6f275bf
|
4
|
+
data.tar.gz: abf191c993c3e3162762cc5bbd60bff655119ab5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7a90bc3626c1b270ebc0c53e529317fc80f2f42a8d7482f944f502d4ff05437208eefed956467afdeea283fea0eadc1198e686b84416ef82cba7a55783ba4fb
|
7
|
+
data.tar.gz: 43e211fd4a782099c3d8e93f21df795d5921bde6127ea85f27af3e1ad99881648d8cb6b26ad009716173e99c4f111ba40df61d0cd8b37c3bd7cf2c4478ffe1c4
|
data/lib/execute.rb
CHANGED
@@ -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
|
-
|
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 >
|
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? && !
|
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
|