Message221865
This problem happens with Python 3.4 as well.
$ cat read_error_file.py
from __future__ import print_function
import os
fname = "/usr/bin/Xorg"
size = os.stat(fname).st_size
print(fname, "stat size:", size)
f = open(fname, "rb")
print("len(f.read()): ", len(f.read()))
f.close()
f = open(fname, "rb")
for i in range(size):
try:
f.read(1)
except IOError:
print("IOError at byte %d" % i)
break
f.close()
$ python3 --version
Python 3.4.1
$ python3 read_error_file.py
/usr/bin/Xorg stat size: 2331776
len(f.read()): 716800
IOError at byte 716800
strace for the first test is:
open("/usr/bin/Xorg", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0755, st_size=2331776, ...}) = 0
ioctl(3, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7fff323ac8b0) = -1 ENOTTY (Inappropriate ioctl for device)
fstat(3, {st_mode=S_IFREG|0755, st_size=2331776, ...}) = 0
lseek(3, 0, SEEK_CUR) = 0
lseek(3, 0, SEEK_CUR) = 0
fstat(3, {st_mode=S_IFREG|0755, st_size=2331776, ...}) = 0
mmap(NULL, 2334720, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f57884cc000
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\265M\4\0\0\0\0\0"..., 2331777) = 716800
read(3, 0x7f578857b030, 1614977) = -1 EIO (Input/output error)
mremap(0x7f57884cc000, 2334720, 720896, MREMAP_MAYMOVE) = 0x7f57884cc000
munmap(0x7f57884cc000, 720896) = 0
write(1, "len(f.read()): 716800\n", 23len(f.read()): 716800
) = 23
close(3) |
|
Date |
User |
Action |
Args |
2014-06-29 17:11:58 | ivank | set | recipients:
+ ivank, pitrou, vstinner, neologix |
2014-06-29 17:11:58 | ivank | set | messageid: <1404061918.82.0.129039948855.issue21090@psf.upfronthosting.co.za> |
2014-06-29 17:11:58 | ivank | link | issue21090 messages |
2014-06-29 17:11:58 | ivank | create | |
|