diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-05-16 18:37:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-16 18:37:56 (GMT) |
commit | acffe20683042e8567eae3bf014d36c0edf9b710 (patch) | |
tree | d69f5ccd4fca797145f57e1285cf06fd4e9090e0 /Tools | |
parent | 45fbca983cee2b6038605d88a8e09b03220f8f0f (diff) | |
download | cpython-acffe20683042e8567eae3bf014d36c0edf9b710.zip cpython-acffe20683042e8567eae3bf014d36c0edf9b710.tar.gz cpython-acffe20683042e8567eae3bf014d36c0edf9b710.tar.bz2 |
[3.13] GH-118943: Fix a race condition when generating jit_stencils.h (GH-119101)
(cherry picked from commit 4702b7b5bdc07d046576b4126cf4e4f5f7145abb)
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/jit/_targets.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py index b020f49..5604c42 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( |