FIFO problems

Steve Holden sholden at holdenweb.com
Thu Sep 11 08:17:29 EDT 2003


"Tobias Pfeiffer" <BoteDesSchattens at web.de> wrote in message
news:bjp0sg$li4db$1 at ID-162581.news.uni-berlin.de...
> 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
condition.

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:
        break
    del line[:-1]
    if line == "bla":
        do something incredibly interesting
    else:
        print line

regards
--
Steve Holden                                  http://www.holdenweb.com/
Python Web Programming                 http://pydish.holdenweb.com/pwp/







More information about the Python-list mailing list