Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-118943: Fix a race condition when generating jit_stencils.h #118957

Merged
merged 5 commits into from
May 16, 2024

Conversation

brandtbucher
Copy link
Member

@brandtbucher brandtbucher commented May 11, 2024

Write to a temporary file first, then rename it to the intended jit_stencils.h file. This keeps other build steps from assuming that the file has been successfully generated when it's still in the process of being written.

CC: @savannahostrowski

@brandtbucher brandtbucher added type-bug An unexpected behavior, bug, or error build The build process and cross-build needs backport to 3.13 bugs and security fixes labels May 11, 2024
@brandtbucher brandtbucher self-assigned this May 11, 2024
Copy link
Contributor

@savannahostrowski savannahostrowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this LGTM. Just one comment.

Tools/jit/_targets.py Show resolved Hide resolved
Copy link
Contributor

@hroncok hroncok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change makes perfect sense and should fix the problem. Hard to test due to the nature of the issue, hence untested.

One question though (and one optional suggestion).

file.write(digest)
if comment:
file.write(f"// {comment}\n\n")
file.write("")
Copy link
Contributor

@hroncok hroncok May 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure what was the purpose of this line, but it is no longer there. I guess it did nothing, correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. Yeah, I think this was originally intended to write a newline, but it was really doing nothing. But I think we do want to add a newline whether or not there's a comment, so I'll move one of them from the comment line to here.

file.write(f"{line}\n")
jit_stencils_new.replace(jit_stencils)
finally:
jit_stencils_new.unlink(True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to guess (and look up) what the boolean stands for. Would you mind using a keyword argument instead?

Suggested change
jit_stencils_new.unlink(True)
jit_stencils_new.unlink(missing_ok=True)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, good suggestion.

@brandtbucher brandtbucher merged commit 4702b7b into python:main May 16, 2024
59 checks passed
@miss-islington-app
Copy link

Thanks @brandtbucher for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 16, 2024
@bedevere-app
Copy link

bedevere-app bot commented May 16, 2024

GH-119101 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build The build process and cross-build type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants