Open
Conversation
Jongy
reviewed
May 1, 2023
gprofiler/utils/fs.py
Outdated
| os.makedirs(path, 0o755, exist_ok=True) | ||
| test_script.write_text("#!/bin/sh\nexit 0") | ||
| test_script.chmod(0o755) | ||
| test_script = NamedTemporaryFile(dir=path, suffix=".sh") |
Contributor
There was a problem hiding this comment.
I think that to have NamedTemporaryFile actually remove the file, you need __exit__ to be called. So the usage should be:
with NamedTemporaryFile(...) as test_script:
do function logic
Contributor
Author
There was a problem hiding this comment.
I wrote a simple test to check it and it gets closed everytime, even with "sys.exit(1) between these lines:
tf = tempfile.NamedTemporaryFile(dir="/home/kitter/Documents/june-gprof/my-gprof-fork/gprofiler", suffix=".tester")
with open(tf.name, "w") as f:
f.write("my-tester")
print(Path(tf.name).read_text())
time.sleep(5)
but I changed it accordingly anyway :)
Jongy
reviewed
May 1, 2023
Jongy
reviewed
May 1, 2023
gprofiler/profilers/perf.py
Outdated
Comment on lines
341
to
345
| # always read its stderr | ||
| # using read1() which performs just a single read() call and doesn't read until EOF | ||
| # (unlike Popen.communicate()) | ||
| assert self._process is not None and self._process.stderr is not None | ||
| logger.debug(f"{self._log_name} run output", perf_stderr=self._process.stderr.read1()) # type: ignore |
Jongy
reviewed
May 1, 2023
gprofiler/profilers/perf.py
Outdated
| run_process( | ||
| [perf_path(), "inject", "--jit", "-o", str(inject_data), "-i", str(perf_data)], | ||
| ) | ||
| perf_data = Path(inject_data.name) |
Contributor
There was a problem hiding this comment.
This creates a problematic flow:
perf_data = temporary file- Exception is raised during
perf script finallyruns and tries to unlinkperf_datawhich is already unlinked.
I suggest you use a 3rd variable (like perf_script_input), then set it to either perf_data OR inject_data, and only unlink perf_data as inject_data is automatically removed.
Jongy
suggested changes
May 1, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Related Issue
Motivation and Context
How Has This Been Tested?
Screenshots
Checklist: