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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • py

    #1

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

    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.r ead(1))

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

    thanks

Working...