summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/_bootstrap.py
diff options
context:
space:
mode:
authorCharles-François Natali <neologix@free.fr>2012-02-22 20:03:09 (GMT)
committerCharles-François Natali <neologix@free.fr>2012-02-22 20:03:09 (GMT)
commit6db1c40b374ecdf7324fa123db4c2202d4f986c9 (patch)
tree47b600185aab1bef493238943aa3a49593dc5ee7 /Lib/importlib/_bootstrap.py
parente887f3135cfedff0e3b5056ff7c9c351fa02c720 (diff)
downloadcpython-6db1c40b374ecdf7324fa123db4c2202d4f986c9.zip
cpython-6db1c40b374ecdf7324fa123db4c2202d4f986c9.tar.gz
cpython-6db1c40b374ecdf7324fa123db4c2202d4f986c9.tar.bz2
Issue #14077: importlib: Fix regression introduced by de6703671386.
Diffstat (limited to 'Lib/importlib/_bootstrap.py')
-rw-r--r--Lib/importlib/_bootstrap.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index f70869e..d10ab2f 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -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