473,545 Members | 2,358 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(oldPa th)
os.rename(newPa th, 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 9743
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_DURAT ION_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
599
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. But any other user produces the following three messages; sem_trywait: Permission denied sem_wait: Permission denied sem_post: Permission denied
1
5576
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 to load a simple xml file, which is in the server machine itself. The script is within a JSP page running apache tom-cat. I am running it with IE6...
1
3678
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 errors. System.ComponentModel.Win32Exception: Access is denied I see ServiceControllerPermission class - but not sure how to use it.
6
4130
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 had to manually install all of the ODBC drivers and the rest of the DLL's, and now I am getting "Access is Denied" errors on any page that uses ADODB....
0
3525
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 original question, the subject line is: ADODB.NET and "Access Denied" I have an ASP.NET page writtein in VB that uses ADODB. I just had to
2
13153
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 XP SP2 / Access 2003 Private Sub MoveFolder(strDestination As String) 'required references: 'Microsoft Office 11.0 Object Library
0
1765
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. Aside from having administrative rights, I have also put myself in the Debugger Users group. I have added ASPNET and even IUSR_SERVERNAME to the...
1
11064
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 understand what users or, preferably, groups, need to have what permissions for basic operation of ASP.NET 2.0. And specifically WHAT permissions should I...
0
1333
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 not visible. Why is this and how can I get around this? If I cannot get around it, how can I get a process associated with a certain file name? To...
0
7487
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7420
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7680
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7934
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5349
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4966
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3459
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1908
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1033
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.