Commit 76ceafcf authored by Samuel E. Giddins's avatar Samuel E. Giddins

[Executable] Dont try and run threads that are no longer alive

parent fd9770ef
......@@ -51,7 +51,6 @@ module Pod
bin = `which #{executable}`.strip
raise Informative, "Unable to locate the executable `#{executable}`" if bin.empty?
require 'open3'
require 'shellwords'
command = command.map(&:to_s)
......@@ -64,13 +63,7 @@ module Pod
stdout, stderr = Indenter.new, Indenter.new
end
status = Open3.popen3(bin, *command) do |i, o, e, t|
out_reader = Thread.new { while s = o.gets; stdout << s; end }
err_reader = Thread.new { while s = e.gets; stderr << s; end }
i.close
[out_reader, err_reader].each(&:run)
t.value
end
status = popen3(bin, command, stdout, stderr)
output = stdout.join("\n") + stderr.join("\n")
unless status.success?
if raise_on_failure
......@@ -82,6 +75,27 @@ module Pod
output
end
private
def self.popen3(bin, command, stdout, stderr)
require 'open3'
Open3.popen3(bin, *command) do |i, o, e, t|
out_reader = Thread.new { while s = o.gets; stdout << s; end }
err_reader = Thread.new { while s = e.gets; stderr << s; end }
i.close
run_readers = lambda do
[out_reader, err_reader].each do |reader|
reader.run if reader.alive?
end
end
run_readers.call
t.value.tap { run_readers.call }
end
end
#-------------------------------------------------------------------------#
# Helper class that allows to write to an {IO} instance taking into account
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment