On Mon, Jan 20, 2014 at 1:54 PM, Robert Klemme
<shortcutter / googlemail.com> wrote:
> On Sun, Jan 19, 2014 at 6:47 PM, Martin Hansen <lists / ruby-forum.com> wrote:
>
>> and it hangs after dumping big.tab. Again, I suspect bad pipe hangling
>> and I uploaded the traces from that one as well as trace_3step.tar. In
>> fact I uploaded code, test files and traces.
>
> One more potential source of issues: you open all the pipes from the
> main process.  However, child processes will inherit those pipe
> objects and if they are not closed there they will keep the pipeline
> alive. That might be the issue you face.

Here's a demo of what I mean:

#!/usr/bin/ruby

r, w = IO.pipe

p2 = fork {
  w.close
  r.each do |line|
    line.chomp!
    puts "Got: '#{line}'"
  end
}

p1 = fork {
  r.close
  10.times {|i| w.puts i}
  w.close
}

r.close
# w.close # uncomment to make hang go away

puts "waiting for #{p2}..."
Process.waitpid p2
puts "finished"


The situation becomes worse with multiple processes and pipes being
generated because they are all inherited by all the processes.

I created a solution that seems to work:
https://gist.github.com/rklemme/8537604

Main difference to your API: I use lambdas as abstraction of work to
do because this is more flexible than your approach with methods in
the Pipe class.  Lambads receive an IO to read from and one to write
to.

Kind regards

robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/