def safe_remove(path):
if not os.path.exists(path):<EOL><INDENT>return<EOL><DEDENT>try:<EOL><INDENT>if os.path.isdir(path) and not os.path.islink(path):<EOL><INDENT>shutil.rmtree(path)<EOL><DEDENT>else:<EOL><INDENT>os.remove(path)<EOL><DEDENT><DEDENT>except OSError:<EOL><INDENT>if os.path.exists(path):<EOL><INDENT>raise<EOL><DEDENT><DEDENT>
Safely remove the given file or directory.

    Works in a multithreaded scenario.