mirror of
https://github.com/python/cpython.git
synced 2025-10-07 23:51:16 +00:00
Silence the FileExistsError which can be raised because of the O_EXCL flag
(as in import.c)
This commit is contained in:
parent
587e75c70b
commit
daaaec9ee7
1 changed files with 7 additions and 7 deletions
|
@ -81,7 +81,9 @@ def _path_absolute(path):
|
||||||
|
|
||||||
|
|
||||||
def _write_atomic(path, data):
|
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'):
|
if not sys.platform.startswith('win'):
|
||||||
# On POSIX-like platforms, renaming is atomic
|
# On POSIX-like platforms, renaming is atomic
|
||||||
path_tmp = path + '.tmp'
|
path_tmp = path + '.tmp'
|
||||||
|
@ -516,12 +518,10 @@ class _SourceFileLoader(_FileLoader, SourceLoader):
|
||||||
raise
|
raise
|
||||||
try:
|
try:
|
||||||
_write_atomic(path, data)
|
_write_atomic(path, data)
|
||||||
except OSError as exc:
|
except (PermissionError, FileExistsError):
|
||||||
# Don't worry if you can't write bytecode.
|
# Don't worry if you can't write bytecode or someone is writing
|
||||||
if exc.errno == errno.EACCES:
|
# it at the same time.
|
||||||
return
|
pass
|
||||||
else:
|
|
||||||
raise
|
|
||||||
|
|
||||||
|
|
||||||
class _SourcelessFileLoader(_FileLoader, _LoaderBasics):
|
class _SourcelessFileLoader(_FileLoader, _LoaderBasics):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue