why are *two* ctrl-D's needed with readline()

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Sat Oct 6 11:50:57 CEST 2001

Fri, 5 Oct 2001 14:34:17 -0400, Steve Holden <sholden at holdenweb.com> pisze:

> Technically ^D terminates transmission, and only raises EOF if this results
> in an empty input buffer, which it does if entered before inputting any
> characters.

On Linux at least ^D just makes read() return what's currently in
the terminal buffer. It doesn't change some permanent EOF state.
When the program tries to read further despite the previous read()
call returned 0, the user will need to generate EOF one more time.

Consider the 'mail' program: when you type ^D to end the mail body,
'mail' asks for Cc:. In case the input is going from the file, the
system will signal EOF to the program the second time immediately,
but a terminal will need to send each EOF marker separately.

So in normal circumstances programs shouldn't try to read after EOF
was seen, because it makes a difference for terminals.

 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
  ^^                      SYGNATURA ZASTĘPCZA

More information about the Python-list mailing list