diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-10-19 21:28:40 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-10-19 21:28:40 (GMT) |
commit | daaaec9ee761f8cdca222ea393968aff9b57db28 (patch) | |
tree | 9e3d7e3387b4b510ff17e731e7f4faf580193d47 /Lib/importlib/_bootstrap.py | |
parent | 587e75c70baac7f0641d3bc93b45ea7af1c30736 (diff) | |
download | cpython-daaaec9ee761f8cdca222ea393968aff9b57db28.zip cpython-daaaec9ee761f8cdca222ea393968aff9b57db28.tar.gz cpython-daaaec9ee761f8cdca222ea393968aff9b57db28.tar.bz2 |
Silence the FileExistsError which can be raised because of the O_EXCL flag
(as in import.c)
Diffstat (limited to 'Lib/importlib/_bootstrap.py')
-rw-r--r-- | Lib/importlib/_bootstrap.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py index 824a31c..1e22438 100644 --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -81,7 +81,9 @@ def _path_absolute(path): def _write_atomic(path, data): - """Best-effort 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.""" if not sys.platform.startswith('win'): # On POSIX-like platforms, renaming is atomic path_tmp = path + '.tmp' @@ -516,12 +518,10 @@ class _SourceFileLoader(_FileLoader, SourceLoader): raise try: _write_atomic(path, data) - except OSError as exc: - # Don't worry if you can't write bytecode. - if exc.errno == errno.EACCES: - return - else: - raise + except (PermissionError, FileExistsError): + # Don't worry if you can't write bytecode or someone is writing + # it at the same time. + pass class _SourcelessFileLoader(_FileLoader, _LoaderBasics): |