From: Tony Arcieri Date: 2010-05-30T02:59:47+09:00 Subject: Re: Non blocking IO during an AJAX request --000e0cd34a8887c2740487bf63d2 Content-Type: text/plain; charset=ISO-8859-1 The semantics of pipes are somewhat tricky and definitely not ideal for this sort of communication. I'm not exactly sure what your use case is, but you might consider placing your message into a service like Redis. Redis 2.0 (still in RC right now) supports "blocking pop", which means your "writer" simply adds a message to a list, then your "reader" attempts a blocking pop. If a message is available the reader will get it immediately, otherwise it blocks until a message is written to the list it's trying to pop from. On Sat, May 29, 2010 at 11:39 AM, 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 > > > Then in a 2nd AJAX request I simply attempt to read the named pipe and > return the string to the browser: > > def results > if File.exists?(PINGFIFO) && File.pipe?(PINGFIFO) > File.open(PINGFIFO, "r") do |f| > render :text => f.readlines > 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!). > -- Tony Arcieri Medioh! A Kudelski Brand --000e0cd34a8887c2740487bf63d2--