code: def safe_remove(path):
      
      if not os.path.exists(path):
          return
  
      try:
          if os.path.isdir(path) and not os.path.islink(path):
              shutil.rmtree(path)
          else:
              os.remove(path)
      except OSError:
          if os.path.exists(path):
              raise
docs: Safely remove the given file or directory.
  
      Works in a multithreaded scenario.