file.readlines() and IOError exceptions

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

    #1

    file.readlines() and IOError exceptions

    Hi everyone,
    I currently have a problem with reading one of my files.
    Normally I'd read files like so:
    overf = 'C:\\overf'
    my_overf = open(overf,'r')
    contents = my_overf.readli nes()
    my_overf.close( )

    now the file Im trying to read has recently had alot of read/writes from
    other users/threads/etc, so every now and again I get a
    IOError: [Errno 9] Bad file descriptor
    I know this has something to do with not being able to read while some
    filehandles are open (or is it?)..I've tried using the following snippet

    try:
    while my_overf.readli ne() != '':
    contents.append (my_overf.readl ine())
    except Exception:
    d = 0 #do nothing

    but it works far slower than normal readlines()...i s there a way to
    check the status of this file and wait until the error has gone (i.e
    wait until other users/programs are done with it)?
    Thanks

Working...