file.readlines() and IOError exceptions

A

Astan Chee

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
 

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

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top