Staging
v0.5.1
https://github.com/python/cpython
Revision 8fba9523cf08029dc2e280d9f48fdd57ab178c9d authored by Victor Stinner on 18 November 2020, 14:36:27 UTC, committed by GitHub on 18 November 2020, 14:36:27 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.
1 parent ce04e71
History
Tip revision: 8fba9523cf08029dc2e280d9f48fdd57ab178c9d authored by Victor Stinner on 18 November 2020, 14:36:27 UTC
bpo-42398: Fix "make regen-all" race condition (GH-23362)
Tip revision: 8fba952
File Mode Size
.azure-pipelines
.github
Doc
Grammar
Include
Lib
Mac
Misc
Modules
Objects
PC
PCbuild
Parser
Programs
Python
Tools
m4
.gitattributes -rw-r--r-- 1.9 KB
.gitignore -rw-r--r-- 1.8 KB
.travis.yml -rw-r--r-- 8.4 KB
CODE_OF_CONDUCT.md -rw-r--r-- 630 bytes
LICENSE -rw-r--r-- 13.6 KB
Makefile.pre.in -rw-r--r-- 67.9 KB
README.rst -rw-r--r-- 10.0 KB
aclocal.m4 -rw-r--r-- 12.8 KB
config.guess -rwxr-xr-x 43.1 KB
config.sub -rwxr-xr-x 35.4 KB
configure -rwxr-xr-x 502.3 KB
configure.ac -rw-r--r-- 169.7 KB
install-sh -rwxr-xr-x 15.0 KB
netlify.toml -rw-r--r-- 82 bytes
pyconfig.h.in -rw-r--r-- 44.9 KB
setup.py -rw-r--r-- 108.5 KB

README.rst

back to top