From: Tanaka Akira Date: 2004-03-26T06:22:44+09:00 Subject: Re: thread/fork/tk nightmares In article , "Ara.T.Howard" writes: > program.each{|stmt| i.puts stmt} > i.flush On Linux, the script blocks at puts. Try puts in a thread as: Thread.new { program.each{|stmt| i.puts stmt} i.flush } Note that your test script works well on Solaris unlike Linux. It seems that select(2) behaves differently on Linux and Solaris. (Since your script uses thread, ruby calls select before a IO operation implicitly.) % cat tst #!/usr/bin/env ruby i = IO.popen(<<'End', 'w') ruby -e 'STDIN.each {|line| sleep 10 }' End def time(tag) t1 = Time.now yield t2 = Time.now printf "%s: %f\n", tag, t2 - t1 end 6.times { time(:select) { IO.select(nil, [i]) } time(:puts) { i.puts "s" } } time(:flush) { i.flush } % ruby -v tst ruby 1.9.0 (2004-03-25) [i686-linux] select: 0.000042 puts: 0.000031 select: 0.028008 puts: 0.000035 select: 9.990686 puts: 0.000029 select: 9.999802 puts: 0.000029 select: 9.999702 puts: 0.000021 select: 9.999867 puts: 0.000028 flush: 0.000007 % ./ruby -v tst ruby 1.9.0 (2004-03-25) [sparc-solaris2.8] select: 0.000161 puts: 0.000074 select: 0.000043 puts: 0.000043 select: 0.000039 puts: 0.000043 select: 0.000066 puts: 0.000043 select: 0.000040 puts: 0.000042 select: 0.000039 puts: 0.000042 flush: 0.000017 On Linux, select waits something - read operation on the other end of the pipe? -- Tanaka Akira