Package: python2.4
Version: 2.4.4-1
Severity: normal
Hello,
compare these two scripts:
import sys
for line in sys.stdin.readlines(): print line
and
import sys
for line in sys.stdin: print line
when run on an interactive terminal, I get this:
$ python test1
ciao
<^D>
ciao
$ python test2
ciao
<^D>
ciao
^D
$
When iterating over sys.stdin, the first end-of-file is ignored and
another one is needed.
This is the relevant strace output when the two ^D are needed:
fstat(0, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 1), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x2b0a17398000
read(0, "ciao\n", 8192) = 5
read(0, "", 7168) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 1), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x2b0a17399000
write(1, "ciao\n", 5) = 5
write(1, "\n", 1) = 1
read(0, "", 8192) = 0
rt_sigaction(SIGINT, {SIG_DFL}, {0x4a0860, [], SA_RESTORER, 0x2b0a16b6e410}, 8)
= 0
futex(0x625660, FUTEX_WAKE, 1) = 0
futex(0x6252a0, FUTEX_WAKE, 1) = 0
futex(0x6252a0, FUTEX_WAKE, 1) = 0
futex(0x6252a0, FUTEX_WAKE, 1) = 0
munmap(0x2b0a17399000, 4096) = 0
exit_group(0) = ?
You can see that the second read returns 0 bytes, but end of file is not
detected another read is attempted again.
When redirecting a file to stdin there is of course no problem because
the second read would normally fail without anyone noticing.
Ciao,
Enrico
-- System Information:
Debian Release: 4.0
APT prefers testing
APT policy: (500, 'testing')
Architecture: amd64 (x86_64)
Shell: /bin/sh linked to /bin/bash
Kernel: Linux 2.6.19.1enrico
Locale: LANG=it_IT.UTF-8, LC_CTYPE=it_IT.UTF-8 (charmap=UTF-8)
Versions of packages python2.4 depends on:
ii libbz2-1.0 1.0.3-6 high-quality block-sorting file co
ii libc6 2.3.6.ds1-8 GNU C Library: Shared libraries
ii libdb4.4 4.4.20-8 Berkeley v4.4 Database Libraries [
ii libncursesw5 5.5-5 Shared libraries for terminal hand
ii libreadline5 5.2-2 GNU readline and history libraries
ii libssl0.9.8 0.9.8c-4 SSL shared libraries
ii mime-support 3.39-1 MIME files 'mime.types' & 'mailcap
ii python2.4-minimal 2.4.4-1 A minimal subset of the Python lan
python2.4 recommends no packages.
-- no debconf information
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]