The following problem has only been tested on linux.
Suppose at a certain time that your machine can
allocate a maximum of X megabytes of memory. Allocating
more than X should result in python MemoryErrors. Also
suppose you have a file containing one big line taking
more than X bytes (Large binary file for example).
In this case, if you read lines from a file through the
file objects iterator, you do NOT get the expected
MemoryError as result, but an empty list.
To reproduce, create a file twice as big as your
machines memory and disable the swap.
If you run the following code:
# import os.path
#
# def test(input):
# print "Testing %s (%sMB)"%(repr(input),
os.path.getsize(input)/(1024.0*1024.0))
# count = 0
# for line in open(input):
# count = count + 1
# print " >> Total Number of Lines: %s"%count
#
# if __name__ == "__main__":
# test('test.small')
# test('test.big')
you'll get something like:
# folke@wladimir devel $ python2.4 bug.py
# Testing 'test.small' (20.0MB)
# >> Total Number of Lines: 1
# Testing 'test.big' (2000.0MB)
# >> Total Number of Lines: 0
|