Bugs item #1523853, was opened at 2006-07-17 13:49
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1523853&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Jarkko Torppa (beeki)
Assigned to: Nobody/Anonymous (nobody)
Summary: 2.4.2 file.read caches EOF state
Initial Comment:
It seems that python 2.4.2 file reading stuff (for l in
f) and (f.read()) cache EOF state. For f.next
documtation hints that there is internal buffer so I
guess that this is somewhat acceptable there. But for
f.read() there is no hint about internal buffering of
the state.
This is somewhat unfortunate as tail -f like
functionality is impossible to implement without doing
lowlevel io (os.read) (as traddional unix has no
select-like functionality on files).
Tested on solaris8. This is either library or
documentation bug.
Code below
def iterline(f):
""" Own function because the internal seems to
buffer EOF
"""
b=[]
while 1:
data=os.read()
print `data`,`b`,f.tell(), \
os.fstat(f.fileno()).st_size
if len(data) == 0:
time.sleep(1)
continue
idx=data.find('\n')
while idx > 0:
line=data[:idx]
if b:
yield ''.join(b) + line
b = []
else:
yield line
data=data[idx+1:]
idx=data.find('\n')
b.append(data)
raise StopIteration
Output
'' [''] 1699424 1699424
(log lines appended here)
'' [''] 1699424 1699647
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1523853&group_id=5470
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com