I have a named pipe created via the os.mkfifo() command. I have two different Python processes accessing this named pipe, process A is reading, and process B is writing. Process A uses the select function to determine when there is data available in the fifo/pipe. Despite the fact that process B flushes after each write call, process A's select function does not always return (it keeps blocking as if there is no new data). After looking into this issue extensively, I finally just programmed process B to add 5KB of garbage writes before and after my real call, and likewise process A is programmed to ignore those 5KB. Now everything works fine, and select is always returning appropriately. I came to this hack-ish solution by noticing that process A's select would return if process B were to be killed (after it was writing and flushing, it would sleep on a read pipe). Is there a problem with flush in Python for named pipes?
A:
The flush operation is irrelevant for named pipes; the data for named pipes is held strictly in memory, and won't be released until it is read or the FIFO is closed.
Ignacio Vazquez-Abrams
2010-01-26 01:00:50
The flush operation can still be relevant if data output to the pipe is buffered at the application level.
Greg Hewgill
2010-01-26 02:09:15
I'm guessing that there is buffering at the application level, does anyone know of any bug?
BrainCore
2010-01-26 03:10:32
+1
A:
What APIs are you using? os.read()
and os.write()
don't buffer anything.
Antoine P.
2010-02-04 15:08:02
+1
A:
To find out if Python's internal buffering is causing your problems, when running your scripts do "python -u" instead of "python". This will force python in to "unbuffered mode" which will cause all output to be printed instantaneously.
pboothe
2010-03-24 15:10:45