Skip to content

Commit 4702b7b

Browse files
authored
pythonGH-118943: Fix a race condition when generating jit_stencils.h (pythonGH-118957)
1 parent ab73bcd commit 4702b7b

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a possible race condition affecting parallel builds configured with
2+
``--enable-experimental-jit``, in which compilation errors could be caused
3+
by an incompletely-generated header file.

Tools/jit/_targets.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,18 @@ def build(
212212
):
213213
return
214214
stencil_groups = asyncio.run(self._build_stencils())
215-
with jit_stencils.open("w") as file:
216-
file.write(digest)
217-
if comment:
218-
file.write(f"// {comment}\n\n")
219-
file.write("")
220-
for line in _writer.dump(stencil_groups):
221-
file.write(f"{line}\n")
215+
jit_stencils_new = out / "jit_stencils.h.new"
216+
try:
217+
with jit_stencils_new.open("w") as file:
218+
file.write(digest)
219+
if comment:
220+
file.write(f"// {comment}\n")
221+
file.write("\n")
222+
for line in _writer.dump(stencil_groups):
223+
file.write(f"{line}\n")
224+
jit_stencils_new.replace(jit_stencils)
225+
finally:
226+
jit_stencils_new.unlink(missing_ok=True)
222227

223228

224229
class _COFF(

0 commit comments

Comments
 (0)