questions about named pipe objects...

Jeff Schwab jeff at schwabcenter.com
Mon Mar 17 13:59:52 EDT 2008


waltbrad wrote:
> I'm proceeding slowly though the Lutz book "Programming Python". I'm
> in the section on named pipes. The script he uses has two functions:
> one for the child the other for the parent.  You start the parent then
> the child:
> 
> python pipefifo.py  #starts the parent
> 
> file /tmp/pipefifo  # shows that the file is a named pipe

You appear to be using something Unix-like.

> python pipefifo.py -child # starts a child process and writes to the
> pipe.
> 
> This is done between two command windows - the first for the parent
> and the second for the child.
> 
> Now, the child's write loop is infinite. So, I used Ctrl-C and stopped
> the process. But the parent's read loop is also infinite and without
> and exception, so it keeps reading from the pipe after the child is
> shutdown even though the lines are empty. So, I had to shut that down
> also.
> 
> I then wanted to start the child process first and see what happened
> when I ran the parent. Well that works but the reads come out in
> random order. This got me wondering about the pipe file itself. So I
> tried to open it with leafpad and found that I couldn't.  I guess
> these files can only be opened by processes?
> 
> Okay. But exactly when does the system brand this file as a named pipe
> and how?

A Unix fifo is only nominally a file.  It's really just a convenient way 
of referring to an in-memory object.
     mkfifo f
     some_prog > f &
     cat f

Is semantically equivalent to:

     some_prog | cat

If you want to peruse the data in your editor, use a regular file, not a 
fifo.  Have the writer (producer, "child" in your example) open it in 
append mode.



More information about the Python-list mailing list