Occasional OSError: [Errno 13] Permission denied on Windows

Alec Wysoker alecw at pobox.com
Fri Jan 6 16:26:30 EST 2006


I tried something not exactly like this, but in the same spirit.  I
don't generally have a list of files I want to delete - just one.  I
try to delete it and if I get errno 13 I sleep for a little while (0.2)
and then try again.  If the same problem then I add 1 sec to the sleep
time and try again.  After sleeping about 10 sec total I give up.

Unfortunately, one of my testers still experiences the problem even
with this fix.  I am surprised that a virus checker or file indexer
would hold onto a file for so long.  Ugh.

Patrick Maupin wrote:
> Tim Peters wrote:
>
> > In that case, anything that burns some time and tries again
> >  will work better.  Replacing gc.collect() with time.sleep() is
> >  an easy way to test that hypothesis; because gc.collect()
> > does an all-generations collection, it can consume measurable time.
>
> An slight enhancement to this hypothesis-tester (which might even
> approach being production-worthy) would be to maintain a list of items
> which were not deleted on a particular pass.  Sleep after each pass,
> then try to kill all the items on the list again.  Maintain a counter
> of the number of passes which have been made since the last time the
> undeleted item list shrank (via a completed deletion), and if the total
> time exceeds 'x' or the number of passes since a completed deletion
> exceeds 'y', then bail and ask the user to help you out.
> 
> Regards,
> Pat




More information about the Python-list mailing list