I want to use
def set_rw(operation, name, exc):
After more investigation, the following appears to work:
def del_rw(action, name, exc): os.chmod(name, stat.S_IWRITE) os.remove(name) shutil.rmtree(path, onerror=del_rw)
In other words, actually remove the file in the onerror function. (You might need to check for a directory in the onerror handler and use rmdir in that case - I didn't need that but it may just be something specific about my problem.