Help: Guide needed in trying to delete/flush the content of a fifo file.
cs at zip.com.au
Tue Nov 16 02:30:06 CET 2010
On 15Nov2010 20:47, MRAB <python at mrabarnett.plus.com> wrote:
| On 15/11/2010 11:03, Ton wrote:
| >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 ...
| 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 think the nearest thing you can do is empty it with a read().
On many systems (AFAIR) a stat of a pipe returns the amount of buffered
data, so you could go (untested - some of the following method names
will probably be wrong, too) something like:
buffered = os.fstat(fifo.fileno())
if buffered > 0:
Of course it is all a bit racy, as data may arrive after the stat,
but arbitrarily "flush"ing the pipe has equivalent problems.
| 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.
I agree with this statement.
Cameron Simpson <cs at zip.com.au> DoD#743
In the end, winning is the only safety. - Kerr Avon
More information about the Python-list