Staging
v0.5.1
https://github.com/python/cpython
Revision 66dd5338a1ca98921c8e6c51228541ef8ed8076a authored by Miss Islington (bot) on 18 November 2020, 16:28:57 UTC, committed by GitHub on 18 November 2020, 16:28:57 UTC

Fix a race condition in "make regen-all" when make -jN option is used
to run jobs in parallel. The clinic.py script now only use atomic
write to write files. Moveover, generated files are now left
unchanged if the content does not change, to not change the file
modification time.

The "make regen-all" command runs "make clinic" and "make
regen-importlib" targets:

* "make regen-importlib" builds object files (ex: Modules/_weakref.o)
  from source files (ex: Modules/_weakref.c) and clinic files (ex:
  Modules/clinic/_weakref.c.h)
* "make clinic" always rewrites all clinic files
  (ex: Modules/clinic/_weakref.c.h)

Since there is no dependency between "clinic" and "regen-importlib"
Makefile targets, these two targets can be run in parallel. Moreover,
half of clinic.py file writes are not atomic and so there is a race
condition when "make regen-all" runs jobs in parallel using make -jN
option (which can be passed in MAKEFLAGS environment variable).

Fix clinic.py to make all file writes atomic:

* Add write_file() function to ensure that all file writes are
  atomic: write into a temporary file and then use os.replace().
* Moreover, write_file() doesn't recreate or modify the file if the
  content does not change to avoid modifying the file modification
  file.
* Update test_clinic to verify these assertions with a functional
  test.
* Remove Clinic.force attribute which was no longer used, whereas
  Clinic.verify remains useful.

(cherry picked from commit 8fba9523cf08029dc2e280d9f48fdd57ab178c9d)
(cherry picked from commit c53c3f400050a7edc92ccb7285a6d7eeb4c37fd2)

Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 73e02ff
Raw File
Tip revision: 66dd5338a1ca98921c8e6c51228541ef8ed8076a authored by Miss Islington (bot) on 18 November 2020, 16:28:57 UTC
bpo-42398: Fix "make regen-all" race condition (GH-23362) (GH-23367)
Tip revision: 66dd533
.gitignore
#####
# First, rules intended to apply in all subdirectories.
# These contain no slash, or only a trailing slash.

*.cover
*.iml
*.o
*.a
*.so*
*.dylib
*.dll
*.orig
*.pyc
*.pyd
*.pyo
*.rej
*.swp
*~
*.gc??
*.profclang?
*.profraw
*.dyn
.gdb_history
.purify
__pycache__
.hg/
.svn/
.idea/
tags
TAGS
.vs/
.vscode/
gmon.out
.coverage
.mypy_cache/

*.exe
!Lib/distutils/command/*.exe

# Ignore core dumps... but not Tools/msi/core/ or the like.
core
!core/


#####
# Then, rules meant for a specific location relative to the repo root.
# These must contain a non-trailing slash (and may also have a trailing slash.)

Doc/build/
Doc/venv/
Doc/.venv/
Doc/env/
Doc/.env/
Include/pydtrace_probes.h
Lib/distutils/command/*.pdb
Lib/lib2to3/*.pickle
Lib/test/data/*
!Lib/test/data/README
/Makefile
/Makefile.pre
Misc/python.pc
Misc/python-embed.pc
Misc/python-config.sh
Modules/Setup.config
Modules/Setup.local
Modules/config.c
Modules/ld_so_aix
Programs/_freeze_importlib
Programs/_testembed
PC/python_nt*.h
PC/pythonnt_rc*.h
PC/*/*.exp
PC/*/*.lib
PC/*/*.bsc
PC/*/*.dll
PC/*/*.pdb
PC/*/*.user
PC/*/*.ncb
PC/*/*.suo
PC/*/Win32-temp-*
PC/*/x64-temp-*
PC/*/amd64
PCbuild/*.user
PCbuild/*.suo
PCbuild/*.*sdf
PCbuild/*-pgi
PCbuild/*-pgo
PCbuild/*.VC.db
PCbuild/*.VC.opendb
PCbuild/amd64/
PCbuild/arm32/
PCbuild/arm64/
PCbuild/obj/
PCbuild/win32/
/autom4te.cache
/build/
/config.cache
/config.log
/config.status
/config.status.lineno
/platform
/profile-clean-stamp
/profile-run-stamp
/pybuilddir.txt
/pyconfig.h
/python-config
/python-config.py
/python.bat
/python-gdb.py
/python.exe-gdb.py
/reflog.txt
/coverage/
/externals/
/htmlcov/
Tools/msi/obj
Tools/ssl/amd64
Tools/ssl/win32

# Two-trick pony for OSX and other case insensitive file systems:
# Ignore ./python binary on Unix but still look into ./Python/ directory.
/python
!/Python/
back to top