Thanks Mrab ... the way of how to use the pipe for the producer as well as the consumer is a bit confusing to me. As i am using the subprocess for both the producer and the consumer as above. Can you please explain me further using a bit of pseudocode. Thanks for ur concern.
In Nov 17, 12:13 am, MRAB <pyt...@mrabarnett.plus.com> wrote: > On 16/11/2010 06:52, Ton wrote: > > > > > On Nov 16, 1:47 am, MRAB<pyt...@mrabarnett.plus.com> wrote: > >> On 15/11/2010 11:03, Ton wrote: > > >>> On Nov 14, 11:55 pm, MRAB<pyt...@mrabarnett.plus.com> wrote: > >>>> On 14/11/2010 14:48, ton ph wrote:> Hi python geeks, > >>>>> I have problem which i have been trying to find out for the past > >>>>> some days, i have a device which feeds info to my fifo continuosly, and > >>>>> a thread of mine reads the > >>>>> fifo continuosly. Now when i change a parameter in the device, it sends > >>>>> me different values. Now my problem is that , i want to get rid of the > >>>>> contents of my previous info which > >>>>> is present in my buffer of the fifo.So i want to flush the fifo content > >>>>> when my device starts sending different info .... i am implementing > >>>>> writing and reading the fifo using two different threads. > >>>>> Please someone guide me solving my problem. > >>>>> I highly apologise everyone in case my post is not so clear... > >>>>> Thanks everyone in advance. > > >>>> When the info changes, the thread which is putting items into the fifo > >>>> could flush it just by getting items from it (using a non-blocking get) > >>>> until it's empty. > > >>> Hi Mrab, > >>> Thanks for your immediate reply , can you please guide me with any > >>> tool or library function which i can flush my fifo content .. i use > >>> os.mkfifo() to make the fifo. Or is there any other way i could do > >>> this ... > >>> Thanks > > >> Ah, you're using pipes; I thought you might've been using a queue. I > >> don't know of a way of flushing a pipe. > > >> I wonder whether it's a good idea for the producer to keep filling the > >> fifo, because the consumer know how 'old' the info is when it arrives, > >> and there's your problem of discarding stale info. Perhaps the producer > >> should wait until the consumer has sent an acknowledgement before > >> sending more info. > > > Thanks Mrab, > > the problem now is that the producer continously dumps the > > information and since i am implementing the producer using the > > subprocess as like this > > > cmd = ['my files'] > > proc = subprocess.Popen(cmd, shell=True, bufsize=0, > > stdout=subprocess.PIPE, stderr=subprocess.STDOUT ) > > > while flag == True: > > line = proc.stdout.read() > > > Now what i want is to synchronise the problem of actual info the > > device is sending and the proper reading as the device is sending and > > not about reading the previous old info in the fifo... hope i have > > made clearer my prob. even i have tried proc.stdout.flush(), to flush > > the previous old info in the fifo. Thnks > > Use two pipes, one each way. The consumer could use send a message to > the producer requesting an update, which the producer could send back > via the other pipe. Thanks marab for your immediate reply. But how actually i go for using pipes in the producer and consumer is a bit doubtful . can you please explain with a pseudocode ... as in my case both producer and consumer are executed using the subprocess as my previous post.... Thanks -- http://mail.python.org/mailman/listinfo/python-list