Python processing of an input byte stream

Alex Martelli aleaxit at yahoo.com
Tue Oct 31 06:53:29 EST 2000


"Erno Kuusela" <erno-news at erno.iki.fi> wrote in message
news:ku66m9gaey.fsf at lasipalatsi.fi...
    [snip]
>  | while 1:
>  |     c = sys.stdin.read(1)
>  |     if not c:
>
> probably works better if you replace the below 2 lines...
>
>  |         time.sleep(1)
>  |         continue
>
> ... with
>            break
>
> :)

No!  Remember the original specs:

>codes for C.  The input byte stream would be
>continuous, so the Python module should expect an
>EOF, similar to running 'tail -f'.

This may not be entirely clear, and perhaps
it's system-dependent, but to me it reads that
the input stream is never-ending, and apparent
end-of-files on it must NOT terminate processing.

"tail -f" has basically (the C equivalent of)
Quinn's code which you suggest replacing: on an
apparent end-of-file, wait a while then try
again.  At least on Unix systems, this works
well when the input-file is a "never-ending
stream" being produced by another process (some
_other_ way, if needed, will have to be designed
to terminate the filter -- asynchronous signals
are the popular approach on Unix).


Alex






More information about the Python-list mailing list