From c02d1689ed01542ffcc5fabc2ac4c7531e8dff3c Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 3 Aug 2018 12:49:09 +0200 Subject: [PATCH] Fix IO loop. --- cmd/lib/capture.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cmd/lib/capture.rb b/cmd/lib/capture.rb index 2510756b79..b300fa0217 100644 --- a/cmd/lib/capture.rb +++ b/cmd/lib/capture.rb @@ -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