I have a C program that writes data to a named pipe and a Python program that reads data from the named pipe, like this:
p = open('/path/to/named/pipe', 'r')
...
data = p.read(size)
When the C program exits, it closes the pipe.
How can I detect this from the Python side? I've tried installing a handler for SIGPIPE, but it seems that SIGPIPE only happens when attempting to write to a closed pipe, not read from it. I also expected that p.read(size) might return a length-zero string because of the EOF at the other end, but actually it just hangs waiting for data.
How can I detect this situation and handle it?
nonblockfor that file descriptor. - Karthikeyan.R.Sopen(...,'r')doesn't do the right thing; it's necessary to useos.open(..., os.O_RDONLY). - Tom