questions about named pipe objects...

W

waltbrad

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

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?
 
W

waltbrad

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.

Well, I take that back. I accidentally had two 'parent' processes
open. So, the reads were sequential but split between two windows.
 
J

Jeff Schwab

waltbrad said:
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.
 
W

waltbrad

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.

Okay. I get it. That's interesting. Wish Lutz explained that. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top