code: def _robust_rmtree(path, logger=None, max_retries=5):
      
  
      for i in range(max_retries):
          try:
              shutil.rmtree(path)
              return
          except OSError as e:
              if logger:
                  info('Unable to remove path: %s' % path)
                  info('Retrying after %d seconds' % i)
              time.sleep(i)
  
      # Final attempt, pass any Exceptions up to caller.
      shutil.rmtree(path)
docs: Try to delete paths robustly .
      Retries several times (with increasing delays) if an OSError
      occurs.  If the final attempt fails, the Exception is propagated
      to the caller. Taken from https://github.com/hashdist/hashdist/pull/116