io - Permission denied doing os.mkdir(d) after running shutil.rmtree(d) in Python -


very in windows 7 console if run python program twice does

if os.path.isdir(d):     shutil.rmtree(d) if not os.path.exists(d):     os.mkdir(d) 

where d name of directory many files, "permission denied" mkdir command. if run once, wait seconds, run again not such error. problem here?

there 3 things come mind:

  1. windows delays file operations in order preserve metadata. if example rename file , create 1 in location, windows has time-window things acls transferred new file. "feature" preserve metadata programs write new file before deleting old one, in order not loose data when fails in middle.

  2. malware scanners hook filesystem operations , perform scan on files, searching malware (or government-critic texts, if you're paranoid, , maybe if you're not paranoid). during scan, other accesses file blocked.

  3. lastly, i'm not sure how shutil.rmtree() implemented, under windows, tree operations implemented not os core shell (i.e. explorer) , executed asynchronously, explain short time window in path still blocked though call returned.

i believe e.g. subversion or rather apache portable runtime stumbled across same problem , worked around retrying delay. solution doesn't win beauty contest, seems job(tm).


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -