i need to read the contents of a file (could be 100kb, could be 500mb,
could be 1gb)...but I want to allow the read to be canceled.

for example, say a user wants to savea file...as it's saving they want
to terminate it...thus stop the read.

I was doing this:


def keepReading():
    # return whether reading should continue
    return readOn

data = []
f = open('somefile.zip', 'rb')
while len(data) < sizeOfFile and keepReading():
    data.append(f.read(1))


....however, this seems to work in python (not in jython, where I get
OutOfMemoryError).  Any suggestions on how to approach this with
perhaps a better way?