PyUtilib / pyutilib

A collection of general Python utilities, including logging and file IO, subprocess management, plugin systems, and workflow management.
BSD 3-Clause "New" or "Revised" License
34 stars 20 forks source link

Add `shutil.rmtree` wrapper that works better on Windows #110

Open dangunter opened 4 years ago

dangunter commented 4 years ago

Due to per-process file locking in windows, shutil.rmtree sometimes fails where it would succeed a second or three later, once Windows thinks the process is done. A utility function that did this would be very useful in projects that use Pyomo/pyutilib, such as IDAES.

dangunter commented 4 years ago

e.g. a function of the flavor:

def rmtree_hard(*args):
    for i in range(3):
        try:
            shutil.rmtree(*args)
            return True
        except:
             time.sleep(1)
    return False