FIFO problems

Steve Holden sholden at
Thu Sep 11 14:17:29 CEST 2003

"Tobias Pfeiffer" <BoteDesSchattens at> wrote in message
news:bjp0sg$li4db$1 at
> Hi!
> I want to write a "client-server-application" (only running on the same
> machine) or actually I've already begun with and have problems with the
> interprocess communication. The server, when started, opens a FIFO and
> opens it with open(infifo, 'r'). Then I check the content of the file
> with
> while 1:
>     line = serverIn.readline()[:-1]
>     if line == "bla":
>         do this
>     else:
>         print line

The problem here is that you aren't testing correctly for and end-of-file

The slice notation you use to "remove the line terminator" unfortunately
gives the same result for an empty line (one containing only a line
terminator) and end-of-file (which returns a line containing no characters
at all).

There are various ways around this. Since you are talking interactive
multi-process stuff here it's probably safest to do somehting like the
following (untested) code:

while 1:
    line = serverIn.readline()
    if not line:
    del line[:-1]
    if line == "bla":
        do something incredibly interesting
        print line

Steve Holden                        
Python Web Programming       

More information about the Python-list mailing list