gh-141592: test_perf_profiler: fix race in perf map cleanup using addCleanup#141593
gh-141592: test_perf_profiler: fix race in perf map cleanup using addCleanup#141593pareshjoshij wants to merge 5 commits intopython:mainfrom
Conversation
…ng addCleanup Signed-off-by: Paresh Joshi <rahulj9223@gmail.com>
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
@bedevere-bot This is a test-only change (fixes race in |
picnixz
left a comment
There was a problem hiding this comment.
There are unnecessary comments, especially those about "buggy" methods. If those method don't exist, don't refer to them and don't say they are buggy. They are not really buggy in some sense, they just don't support parallel execution.
| # | ||
| # We've removed the buggy setUp and tearDown methods. | ||
| # They caused race conditions by scanning /tmp for `perf-*.map` files. | ||
| # Instead, we now use `addCleanup()` inside each test to delete | ||
| # the *specific* files we know that test created. | ||
| # |
There was a problem hiding this comment.
This comment should not be kept. It refers to something that doesn't exist anymore.
| We register this with addCleanup() to make sure it runs | ||
| even if the test assertions fail. |
There was a problem hiding this comment.
This part of the docstring is unnecessary.
| env = {**os.environ, "PYTHON_JIT": "0"} | ||
| with subprocess.Popen( | ||
|
|
||
| # Start the subprocess... |
| # ...and immediately register a cleanup task for its PID. | ||
| # This is guaranteed to run after the test. |
| def foo(): | ||
| pid = os.fork() | ||
| if pid == 0: | ||
| # We're in the child process |
There was a problem hiding this comment.
Please avoid adding unnecessary redundant comments.
| # | ||
| # No setUp or tearDown needed! | ||
| # |
There was a problem hiding this comment.
Remove this comment. It's not necessary.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Signed-off-by: Paresh Joshi <rahulj9223@gmail.com>
|
Done, @picnixz!
I have made the requested changes; please review again. |
|
Thanks for making the requested changes! @picnixz: please review the changes made to this pull request. |
…mments) Signed-off-by: Paresh Joshi <rahulj9223@gmail.com>
|
Done, @picnixz!
I have made the requested changes; please review again. |
|
Thanks for making the requested changes! @picnixz: please review the changes made to this pull request. |
| with temp_dir() as script_dir: | ||
| script = make_script(script_dir, "perftest", code) | ||
| env = {**os.environ, "PYTHON_JIT": "0"} | ||
|
|
There was a problem hiding this comment.
You can now remove the extra blank line.
| if "perf.data" not in stdout: | ||
| return False | ||
|
|
||
| # Check that we can run a simple perf run |
There was a problem hiding this comment.
Keep existing comments since they are unrelated to the PR.
|
|
||
| self.assertEqual(process.returncode, 0) | ||
| self.assertNotIn("Error:", stderr) | ||
|
|
There was a problem hiding this comment.
Remove this blank line (IOW, don't change blank lines)
| self.perf_files = set(pathlib.Path("/tmp/").glob("jit*.dump")) | ||
| self.perf_files |= set(pathlib.Path("/tmp/").glob("jitted-*.so")) |
There was a problem hiding this comment.
Those files are no more deleted. So the same should be done for jit-related files.
|
Done, @picnixz!
I have made the requested changes; please review again. |
|
Thanks for making the requested changes! @picnixz: please review the changes made to this pull request. |
picnixz
left a comment
There was a problem hiding this comment.
I see many new lines. What happened? was it an AI-aided PR?
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Signed-off-by: Paresh Joshi <rahulj9223@gmail.com>
b0365b4 to
d14cac1
Compare
|
@picnixz You were right to ask, my apologies. I did use AI help to refactor the cleanup logic, and it inserted all those extra newlines. In my hurry to push the fix, I accidentally pushed that working file instead of the final version I had corrected myself. I've just pushed a fix by amending the last commit. This new file is the correct one, and it's clean. Sorry for the noise. |
|
Thanks for making the requested changes! @picnixz: please review the changes made to this pull request. |
picnixz
left a comment
There was a problem hiding this comment.
This change is incorrect. Now all tests inherit from the same test and we have multiple tests being executed redundantly. In addition, the JIT files should only be removed if we use -Xperf_jit and not for the other runs.
Please read https://devguide.python.org/getting-started/generative-ai/ about our policy on using AI.
| """Helper to safely delete a specific perf map file.""" | ||
| unlink(f"/tmp/perf-{pid}.map") | ||
|
|
||
| def _cleanup_jit_files(self): |
There was a problem hiding this comment.
Why are we clearing JIT files when testing PerfTrampoline?
| if activate_trampoline: | ||
| return run_perf(script_dir, sys.executable, "-Xperf", script) | ||
| return run_perf(script_dir, sys.executable, script) | ||
| class TestPerfProfiler(TestPerfTrampoline, TestPerfProfilerMixin): |
There was a problem hiding this comment.
Why is thius one also a perf trampoline check?
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
The test suite in
Lib/test/test_perf_profiler.pypreviously usedsetUp/tearDownto scan/tmpforperf-*.mapfiles and delete any that appeared after the test started.This creates a race condition when tests run in parallel (e.g.,
make -j, CI,pytest-xdist): one test deletes map files belonging to another, leading to:/tmpFix
/tmpscanning insetUp/tearDownaddCleanup(self._cleanup_perf_map, pid)for every subprocess PIDTestPerfTrampolineTestPerfProfilertest_pre_fork_compilerun_perf()already usestemp_dir()→ no cleanup neededTesting
Verified in GitHub Codespaces (Linux, India/IST):