Intermittent "permission denied" errors when using os.rename and a recently deleted path??

Russell Warren russandheather at gmail.com
Thu Jul 27 17:43:37 EDT 2006


>     Does it actually tell you the target is the problem? I see an
> "OSError: [Errno 17] File exists" for that case, not a permission error.
> A permission error could occur, for example, if GDS has the source open
> or locked when you call os.rename.

No it doesn't tell me the target is the issue... you are of course
right that it could be either.  I did some looking to see if/why GDS
would lock files at any time while scanning but didn't turn up anything
useful so far.  I'd be surprised if it did as that would be one heck of
an annoying design flaw.

Anyway - the retry-on-failure workaround seems to prevent it from
happening, although it still seems very hackish and I don't like it:

      ...
      if os.path.exists(path1): os.remove(path1)
      startTime = time.clock()
      while 1:
        try:
          os.rename(self.path2, self.path1)
          break
        except OSError:
          if (time.clock() - startTime) > MAX_RETRY_DURATION_s:
            raise
          else:
            time.sleep(0)
       ...

It feels very weird to have to verify a simple operation like this, but
if it works it works.

Russ




More information about the Python-list mailing list