From: Brandt Bucher Date: Thu, 16 May 2024 16:11:42 +0000 (-0400) Subject: GH-118943: Fix a race condition when generating jit_stencils.h (GH-118957) X-Git-Tag: v3.14.0a1~1891 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4702b7b5bdc07d046576b4126cf4e4f5f7145abb;p=thirdparty%2FPython%2Fcpython.git GH-118943: Fix a race condition when generating jit_stencils.h (GH-118957) --- diff --git a/Misc/NEWS.d/next/Build/2024-05-11-15-11-30.gh-issue-118943.VI_MnY.rst b/Misc/NEWS.d/next/Build/2024-05-11-15-11-30.gh-issue-118943.VI_MnY.rst new file mode 100644 index 000000000000..4e886be034fb --- /dev/null +++ b/Misc/NEWS.d/next/Build/2024-05-11-15-11-30.gh-issue-118943.VI_MnY.rst @@ -0,0 +1,3 @@ +Fix a possible race condition affecting parallel builds configured with +``--enable-experimental-jit``, in which compilation errors could be caused +by an incompletely-generated header file. diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py index b020f49cf4a2..5604c429bcf8 100644 --- a/Tools/jit/_targets.py +++ b/Tools/jit/_targets.py @@ -212,13 +212,18 @@ class _Target(typing.Generic[_S, _R]): ): return stencil_groups = asyncio.run(self._build_stencils()) - with jit_stencils.open("w") as file: - file.write(digest) - if comment: - file.write(f"// {comment}\n\n") - file.write("") - for line in _writer.dump(stencil_groups): - file.write(f"{line}\n") + jit_stencils_new = out / "jit_stencils.h.new" + try: + with jit_stencils_new.open("w") as file: + file.write(digest) + if comment: + file.write(f"// {comment}\n") + file.write("\n") + for line in _writer.dump(stencil_groups): + file.write(f"{line}\n") + jit_stencils_new.replace(jit_stencils) + finally: + jit_stencils_new.unlink(missing_ok=True) class _COFF(