]> granicus.if.org Git - python/commitdiff
Issue #14077: importlib: Fix regression introduced by de6703671386.
authorCharles-François Natali <neologix@free.fr>
Wed, 22 Feb 2012 20:03:09 +0000 (21:03 +0100)
committerCharles-François Natali <neologix@free.fr>
Wed, 22 Feb 2012 20:03:09 +0000 (21:03 +0100)
Lib/importlib/_bootstrap.py

index f70869eac074c1d5b795d67ad1ee24b06dfc9a3f..d10ab2f1f4db2c4da7defaf9dc54f9bb934756c1 100644 (file)
@@ -128,7 +128,9 @@ def _path_absolute(path):
 
 
 def _write_atomic(path, data):
-    """Function to write data to a path atomically."""
+    """Best-effort function to write data to a path atomically.
+    Be prepared to handle a FileExistsError if concurrent writing of the
+    temporary file is attempted."""
     # id() is used to generate a pseudo-random filename.
     path_tmp = '{}.{}'.format(path, id(path))
     fd = _os.open(path_tmp, _os.O_EXCL | _os.O_CREAT | _os.O_WRONLY, 0o666)
@@ -595,8 +597,9 @@ class _SourceFileLoader(_FileLoader, SourceLoader):
                 return
         try:
             _write_atomic(path, data)
-        except PermissionError:
-            # Don't worry if you can't write bytecode.
+        except (PermissionError, FileExistsError):
+            # Don't worry if you can't write bytecode or someone is writing
+            # it at the same time.
             pass