From: ts Date: 2003-12-13T03:17:35+09:00 Subject: Re: Bug with fifos in Linux? >>>>> "D" == Derek Lewis writes: D> Should that be File::NONBLOCK and File::RDONLY? I just changed my code to IO:: is just fine D> use those, but it's still behaving strangly. D> Some more sample code based on the previous: D> FIFO_FILE='/tmp/rubyfifo' D> `mkfifo "#{FIFO_FILE}"` unless test(?e, FIFO_FILE) add this Thread.abort_on_exception = true and you'll see the error D> thread = Thread.new { D> puts "Opening fifo for writing" D> File.open(FIFO_FILE, File::NONBLOCK | File::WRONLY) { |file| D> puts "Starting write loop" D> while true D> puts "Thread is running" D> sleep 1 D> file.puts "Thread is running" D> end D> } D> } svg% cat b.rb #!/usr/bin/ruby FIFO_FILE='/tmp/rubyfifo' `mkfifo "#{FIFO_FILE}"` unless test(?e, FIFO_FILE) Thread.abort_on_exception = true thread = Thread.new { begin puts "Opening fifo for writing" File.open(FIFO_FILE, IO::NONBLOCK | IO::WRONLY) { |file| puts "Starting write loop" while true puts "Thread is running" sleep 1 file.puts "Thread is running" file.flush end } rescue p $! sleep 1 retry end } puts "Opening fifo for reading" File.open(FIFO_FILE, IO::NONBLOCK | IO::RDONLY) { |file| puts "Reading from fifo" sleep 2 while !file.eof line = file.gets("\n") puts "Read from fifo: #{line}" end puts "exited read loop" } svg% svg% b.rb Opening fifo for writing # Opening fifo for reading Reading from fifo Opening fifo for writing Starting write loop Thread is running Thread is running Read from fifo: Thread is running Thread is running Read from fifo: Thread is running Thread is running Read from fifo: Thread is running Thread is running Read from fifo: Thread is running ^Z [4]+ Stopped b.rb svg% Guy Decoux