jython/python: read file and allow read to be terminated

P

py

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?

thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top