sys.stdin and two CTRL-Ds

Christoph Haas email at christoph-haas.de
Sat Jul 1 15:02:20 EDT 2006


Hi...

I encountered a problem that - according to my google search - other
people have found, too. Example code:

import sys
for line in sys.stdin:
   print line

Running this code in Python 2.3 or 2.4 has the problem that I need to
send two EOFs (Ctrl-D) to break out of that loop.

Use case is a piped Python script that I run as a "CustomLog" pipe for
an Apache web server. I want to run all the log output through that pipe
but haven't had much luck. First it takes ages until the script
processes the input (even though I ran Python with "-u" to make it
unbuffered) and then the script needs one EOF to do something with the
input and a second EOF to break out of the loop.

Is this a bug? I'm close to write a Perl script for this case. :(

Regards
 Christoph



More information about the Python-list mailing list