[Python-checkins] cpython: Issue #14077: importlib: Fix regression introduced by de6703671386.

charles-francois.natali python-checkins at python.org
Wed Feb 22 21:03:46 CET 2012


http://hg.python.org/cpython/rev/27d31f0c4ad5
changeset:   75185:27d31f0c4ad5
parent:      75179:90d302951add
user:        Charles-François Natali <neologix at free.fr>
date:        Wed Feb 22 21:03:09 2012 +0100
summary:
  Issue #14077: importlib: Fix regression introduced by de6703671386.

files:
  Lib/importlib/_bootstrap.py |  9 ++++++---
  1 files changed, 6 insertions(+), 3 deletions(-)


diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -128,7 +128,9 @@
 
 
 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 @@
                 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
 
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list