file.readlines() and IOError exceptions

Astan Chee stanc at al.com.au
Tue Jul 11 20:04:57 EDT 2006


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.readlines()
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.readline() != '':
      contents.append(my_overf.readline())
except Exception:
     d = 0 #do nothing

but it works far slower than normal readlines()...is 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




More information about the Python-list mailing list