473,320 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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).

The code snippet that gets repeatedly called is here:

...
if os.path.exists(oldPath):
os.remove(oldPath)
os.rename(newPath, oldPath)
...

And I get the permission denied exception on the os.rename line.
Somehow the rename target is still locked? I don't get it.

I found a post that seemed to refer to precisely this problem:
http://groups.google.com/group/comp....c19db11d8b6d4e

However - this post describes a case where there are multiple threads
making use of other os calls. I am running a single threaded
application and still getting this problem. ie: the suggested fix does
not work for me.

I'm trying to see if implementing a "trap the exception and try again,
but not too many times" hack fix will do the trick, but I'm not a big
fan of this "solution", and at this point I'm not entirely certain it
will work because confirming that it *did* work is tough (it is very
difficult to repeatably create the problem).

Does anyone know of a real solution to this problem, or know what
exactly is happening so that I can work out a proper solution?

Thanks,
Russ

Jul 26 '06 #1
4 9669
Russell Warren:
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
Jul 26 '06 #2
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.

Jul 26 '06 #3
Russell Warren:
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
Jul 27 '06 #4
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

Jul 27 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Hudson | last post by:
Hi, I have just recently build python 2.3.3 on an AIX 5.2 version using gcc v3.3.2 (i built python as root and installed gcc from a rpm file). When we run any python script as root they work. ...
1
by: Darren Lew | last post by:
Hi there, I have this problem which is really driving me nuts for a couple of days. Glad if any help or suggestion is given Javascript will give me a pop-up error "Access is denied" when i try...
1
by: Ron | last post by:
I have a asp.net application that uses the above class to open, get status and start/stop a service. I can get the Status of my Service, but can't start/stop it. I keep getting Access Denied...
6
by: ASP.Confused | last post by:
I have an ASP.NET page writtein in VB that uses ADODB. I just had to force-install MDAC 2.8 after I tried to rollback to 2.6 (my web host uses this, and I wanted to be compatible with them.) I...
0
by: ASP.Confused | last post by:
The old message looked a little stale, so I am re-posting it here. Anybody have any ideas of what I could do?!? The previous responses to this question are below. If you want to look at the...
2
by: deko | last post by:
Why am I getting: "Error Number 70: Permission denied" when trying to move a folder with the Microsoft Scripting Runtime? Is there some security setting I don't know about? Platform: Windows...
0
by: Rico | last post by:
Helolo, I have an ASP.NET application on a Windows 2003 Server machine WITHOUT VS. I am working on an XPPro machine with VS 2003. I have installed the remote debugging components on the server....
1
by: Alex Maghen | last post by:
I'm getting the error "HTTP Error 403.1 - Forbidden: Execute access is denied" when I try to reach my ASPX pages. Before I go giving Windows permissions to my docroot, etc., I want to...
0
by: Michael Leithold, WWK | last post by:
Hello, If I loop through all the processes on my machine, for some processes I get "Access Denied" when trying to read the file name associated with the process. Also some other properties are...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.