Python tempfile.TemporaryDirectory on Windows

Python tempfile is generally robust. TemporaryDirectory(ignore_cleanup_errors=True) fixes the Windows corner case on exiting a tempfile context manager such as cloning a Git repo into the TemporaryDirectory.

import tempfile

with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as tmpdir:
    # create subdirectories, make files, git clone, etc.
    # the context manager attempts to recursively delete "tmpdir" on exit

If there is a PermissionError, the temporary directory remains until the operating system cleans up the temporary directory.