FIFO problems

Tobias Pfeiffer BoteDesSchattens at web.de
Thu Sep 11 14:54:31 EDT 2003


Hi!

"Steve Holden" <sholden at holdenweb.com> wrote in
news:tJZ7b.67$o71.53 at news2.central.cox.net: 

>> 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.

So the end-of-file-thingy also ends a line for the readline-command, I 
suppose? OK, would make sense for normal file read-processes... *grin*

> 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

as changed:
    	line = line[:-1]

>     if line == "bla":
>         do something incredibly interesting
>     else:
>         print line

In which case will the "if not line" condition be true? When there is 
an end-of-file? But I just don't want it to break, I want it to 
continue and wait for a somewhat useful line, e.g. if another client 
connects.

Bye and thanks for your help
Tobias




More information about the Python-list mailing list