diff options
Diffstat (limited to 'Lib/importlib/_common.py')
-rw-r--r-- | Lib/importlib/_common.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Lib/importlib/_common.py b/Lib/importlib/_common.py index 74654b34ed5..9b126f31749 100644 --- a/Lib/importlib/_common.py +++ b/Lib/importlib/_common.py @@ -87,14 +87,16 @@ def _tempfile(reader, suffix=''): # properly. fd, raw_path = tempfile.mkstemp(suffix=suffix) try: - os.write(fd, reader()) - os.close(fd) + try: + os.write(fd, reader()) + finally: + os.close(fd) del reader yield pathlib.Path(raw_path) finally: try: os.remove(raw_path) - except (FileNotFoundError, PermissionError): + except FileNotFoundError: pass |