Discussion:
Intermittent "permission denied" errors when using os.rename and a recently deleted path??
Russell Warren
2006-07-27 21:43:37 UTC
Permalink
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
Neil Hodgson
2006-07-27 06:59:48 UTC
Permalink
I'm actually running both... but I would think that once os.remove
returns that the file is actually gone from the hdd. Why would either
application be blocking access to a non-existent file?
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.

Neil
Neil Hodgson
2006-07-26 22:50:47 UTC
Permalink
I've been having a hard time tracking down a very intermittent problem
where I get a "permission denied" error when trying to rename a file to
something that has just been deleted (on win32).
Are you running a background file accessing tool like Google Desktop
Search or an anti-virus application? If so, try turning them off as a test.

Neil
Russell Warren
2006-07-26 23:09:24 UTC
Permalink
Post by Neil Hodgson
Are you running a background file accessing tool like Google Desktop
Search or an anti-virus application? If so, try turning them off as a test.
I'm actually running both... but I would think that once os.remove
returns that the file is actually gone from the hdd. Why would either
application be blocking access to a non-existent file?

Of course, my thinking is obviously wrong since I do get the permission
problem... I will definitely try disabling those. Now if only I could
reproducably repeat it to make testing easier. :(

Another thing is that I certainly do want the code to work in the
presence of such tools.
Russell Warren
2006-07-26 21:21:46 UTC
Permalink
This post might be inappropriate. Click to display it.
Loading...