shutil.rmtree raises "OSError: [Errno 39] Directory not empty" exception

Maria Liukis liukis at usc.edu
Sat Jul 11 02:30:56 CEST 2009


Thanks for pointing out the parameters for ignore_errors and an  
onerror callback function.

I have been running this code for more than an year, and this is the  
very first time I see the problem. We switched to the NFS mounted  
storage though, but there is nothing unusual logged by the system in  
the /var/log/messages.

I checked the permissions - the directory is still there and has  
exactly the same permissions as other successfully copied and removed  
directories (the very same process creates the directory and later  
removes it). The directory is empty though - so the process removed  
all the entries in it, then some kind of an error occured that  
triggered the exception.

There are lots of similar directories that the process creates and  
removes, but only one of them raised an exception.

Thanks,
Masha
--------------------
liukis at usc.edu



On Jul 10, 2009, at 5:10 PM, Tim Chase wrote:

>>      shutil.rmtree(filename)
>>    File "/usr/lib64/python2.5/shutil.py", line 178, in rmtree
>>      onerror(os.rmdir, path, sys.exc_info())
>>    File "/usr/lib64/python2.5/shutil.py", line 176, in rmtree
>>      os.rmdir(path)
>> OSError: [Errno 39] Directory not empty: /path/to/my/dir
>> According to the documentation, shutil.rmtree should not care  
>> about  directory being not empty.
>
> This sounds suspiciously like a permission issue.  rmtree()  
> *should* walk the tree removing items *if it can*.  If a file can't  
> be deleted, it treats it as an error.  rmtree() takes parameters  
> for ignore_errors and an onerror callback function, so you can  
> catch these error conditions.
>
> -tkc
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090710/39b997aa/attachment.html>


More information about the Python-list mailing list