From: Gary Wright Date: 2010-05-30T03:37:55+09:00 Subject: Re: Non blocking IO during an AJAX request On May 29, 2010, at 1:39 PM, Zundra Daniel wrote: > I realize this is a Ruby mailing list but I have a Ruby/Rails question that > seems to fall more on the Ruby side of the fence. I have a library file > that creates a named pipe and writes the results of ping to the pipe. This > method is called via a get AJAX request to kick off the process. > > def self.run(address) > Fifo.open(PINGFIFO) > > Thread.new { > IO.popen "ping -c 10 localhost" do |f| > until f.eof? > Fifo.write(f.gets, PINGFIFO) > end > end > } > end > > The problem is the 2nd AJAX request simply hangs indefinitely. If I tail > the pipe I can see data being written to it. Does anyone have any insight > into why this is happening? It seemed like a simple enough problem but this > one is throwing me for a loop (har!). My first thought is buffering. I'm not sure what the semantics of Fifo.open and Fifo.write are in your code since 'Fifo' isn't a standard Ruby class. It also seems strange that you are calling Fifo.open but not capturing a return value to be used anywhere. Perhaps you need to call flush somewhere after Fifo.write to ensure the data is actually written to the fifo? That might explain why your send request is blocking since the data isn't in the fifo yet. Gary Wright