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

Discussion in 'Python' started by py, Jan 27, 2006.

  1. py

    py Guest

    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
     
    py, Jan 27, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David McNab
    Replies:
    0
    Views:
    499
    David McNab
    Apr 9, 2004
  2. Jeff
    Replies:
    2
    Views:
    958
    clintonG
    Sep 19, 2006
  3. Divya Prakash
    Replies:
    0
    Views:
    442
    Divya Prakash
    Dec 19, 2006
  4. Pinegar, Kent T

    FW: [Jython-users] Jython Licensing Question

    Pinegar, Kent T, Jul 24, 2008, in forum: Python
    Replies:
    0
    Views:
    355
    Pinegar, Kent T
    Jul 24, 2008
  5. Ryan Taylor
    Replies:
    1
    Views:
    692
    Ryan Taylor
    Sep 9, 2004
Loading...

Share This Page