[Python-bugs-list] [ python-Bugs-470634 ] readlines() on linux requires 2 ^D's (original) (raw)

noreply@sourceforge.net noreply@sourceforge.net
Fri, 12 Oct 2001 10:16:54 -0700


Bugs item #470634, was opened at 2001-10-12 10:06 You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=105470&aid=470634&group_id=5470

Category: Python Interpreter Core Group: Platform-specific Status: Open Resolution: None Priority: 5 Submitted By: Nobody/Anonymous (nobody) Assigned to: Nobody/Anonymous (nobody) Summary: readlines() on linux requires 2 ^D's

Initial Comment: Platform:

This bug has been confirmed on Python 1.5.2, 2.0.1, and 2.1.1 running on Debian Linux 2.2 w/kernel 2.4.9 and libc6 2.2.4, as well as Python 1.5.2 running on Debian Linux 2.0 w/kernel 2.0.38 and libc6 2.0.7.

It has been found not to happen with Python 2.1.1 on Solaris 8 and Cygwin.

Bug Description: When using the standard idiom:

for line in sys.stdin.readlines(): print line

...to loop through lines submitted to stdin, and providing that input interactively (i.e. typing at the console), it is necessary to press ^D twice at the start of line of input to terminate input. The behavior can be noticed both in python's interactive mode and when running a script. Redirected input does not show this problem, that is if the above lines are contained in myscript.py, and you execute:

cat | myscript.py

A single ^D is sufficient to terminate inputs.

Also, the problem is unique to the "readlines()" method. If you code the loop as

for line in sys.stdin.read().splitlines():

then a single ^D at the beginning of a line is sufficient to terminate input.


Comment By: Guido van Rossum (gvanrossum) Date: 2001-10-12 10:16

Message: Logged In: YES user_id=6380

Confirmed on Linux (RH 6.2) with 2.2 from CVS too.

I think it's probably a logic error in readlines() -- maybe the first EOF ends it reading the current line, but then it needs another EOF to break out of the loop.


You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=105470&aid=470634&group_id=5470