Skip to content

Commit

Permalink
External process output should be read asynchronously to avoid deadlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Nov 30, 2017
1 parent 4b33941 commit 6376733
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions rake-tasks/buck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,25 @@ def self.buck_cmd(command, args, &block)
args ||= []
buck.push(command)
buck.push(*args)
puts buck.join(' ')

output = ''
Open3.popen3(*buck) do |stdin, stdout, stderr, wait|
stdin.close

while (error = stderr.gets)
STDERR.print(error)
Thread.new do
while (error = stderr.gets)
STDERR.print(error)
end
end

while (line = stdout.gets)
output << line
STDOUT.print line
Thread.new do
while (line = stdout.gets)
output << line
STDOUT.print line
end
end

stdin.close

raise "#{buck.join(' ')} failed with exit code: #{wait.value.exitstatus}" unless wait.value.success?
end

Expand Down

0 comments on commit 6376733

Please sign in to comment.