Fix IO loop.

This commit is contained in:
Markus Reiter
2018-08-04 13:30:20 +02:00
parent 8e51a9932e
commit c02d1689ed
+10 -4
View File
@@ -12,8 +12,8 @@ def capture
begin
yield
ensure
$stdout.flush
$stderr.flush
w.flush
w.close
end
end
thread.abort_on_exception = true
@@ -22,9 +22,15 @@ def capture
loop do
begin
output << r.readline_nonblock || ""
selected = IO.select([r], [], [], 1)
if reader = selected&.dig(0, 0)
output << (reader.readline_nonblock || "")
else
break if w.closed?
end
rescue IO::WaitReadable
break unless thread.alive?
retry
end
end