python - IOError [Errno 13] when using numpy.loadtext? -
i have function polls folder new files, loads them using numpy.loadtext when shows up. function called while loop runs 30 seconds. function works of time, files, seemingly @ random, error ioerror: [errno 13] permission denied: 'myfilename1.txt'. here content of function:
before = dict([(f, none) f in os.listdir(mydir)]) while 1: after = dict([(f, none) f in os.listdir(mydir)]) added = [f f in after if f not in before] # new file if added: raw = numpy.loadtxt(mydir + added[0]) return raw
any idea on why happening? polls , reads text files incoming, spits error , can't find systematic reason why.
update:
has using full path loadtxt. when change working directory directory files are, no longer permissions error.
have tried opening file read only, may conflict if file accessed application (or still being created).
# new file if added: open(mydir + added[0], 'r') f: raw = numpy.loadtxt(f)
you try form of ioerror handling waits little while , tries again
import time before = dict([(f, none) f in os.listdir(mydir)]) added = false while 1: # new file if added: try: raw = numpy.loadtxt(mydir + added[0]) return raw except ioerror: time.sleep(5) else: after = dict([(f, none) f in os.listdir(mydir)]) added = [f f in after if f not in before]
Comments
Post a Comment