Skip to content

Commit

Permalink
pythonGH-118943: Handle races when moving jit_stencils.h (pythonGH-12…
Browse files Browse the repository at this point in the history
…0690)

Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
  • Loading branch information
hroncok and Eclips4 committed Aug 5, 2024
1 parent 5bd7291 commit 44659d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a possible race condition affecting parallel builds configured with
``--enable-experimental-jit``, in which :exc:`FileNotFoundError` could be caused by
another process already moving ``jit_stencils.h.new`` to ``jit_stencils.h``.
7 changes: 6 additions & 1 deletion Tools/jit/_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,12 @@ def build(
file.write("\n")
for line in _writer.dump(stencil_groups):
file.write(f"{line}\n")
jit_stencils_new.replace(jit_stencils)
try:
jit_stencils_new.replace(jit_stencils)
except FileNotFoundError:
# another process probably already moved the file
if not jit_stencils.is_file():
raise
finally:
jit_stencils_new.unlink(missing_ok=True)

Expand Down

0 comments on commit 44659d3

Please sign in to comment.