Skip to content

Conversation

@roi-granulate
Copy link
Contributor

@roi-granulate roi-granulate commented Sep 3, 2024

Description

cleanup each instance of PyPerf staticx directories on termination.

Related Issue

We experienced where there were a-lot of staticx tempdirs leftovers.

Motivation and Context

How Has This Been Tested?

Screenshots

Checklist:

  • I have read the CONTRIBUTING document.
  • I have updated the relevant documentation.
  • I have added tests for new logic.

@roi-granulate roi-granulate requested a review from d3dave September 3, 2024 13:14
@roi-granulate roi-granulate requested a review from d3dave September 4, 2024 08:45
self._pyperf_staticx_tmpdir: Optional[Path] = None
if os.environ.get("TMPDIR", None) is not None:
# We want to create a new level of hirerachy in our current staticx tempdir.
self._pyperf_staticx_tmpdir = Path(os.environ["TMPDIR"]) / random_prefix()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self._pyperf_staticx_tmpdir = Path(os.environ["TMPDIR"]) / random_prefix()
self._pyperf_staticx_tmpdir = Path(os.environ["TMPDIR"]) / "pyperf_" + random_prefix()

@Jongy
Copy link
Contributor

Jongy commented Sep 22, 2024

@d3dave are you able to complete the review this week?

@d3dave
Copy link
Contributor

d3dave commented Sep 22, 2024

@d3dave are you able to complete the review this week?

CI is red

@roi-granulate
Copy link
Contributor Author

@Jongy @d3dave I’ll fix CI in a different PR #924

@roi-granulate
Copy link
Contributor Author

Merged the CI fix from master

Comment on lines -150 to +158
# ensure `TMPDIR` env is propagated to the child processes (used by staticx)
if "TMPDIR" not in env and "TMPDIR" in os.environ:
if tmpdir is not None:
tmpdir.mkdir(exist_ok=True)
env["TMPDIR"] = tmpdir.as_posix()
elif "TMPDIR" not in env and "TMPDIR" in os.environ:
# ensure `TMPDIR` env is propagated to the child processes (used by staticx)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’m not sure this is the right approach
maybe should we use tmpdir always relative to the current env[“TMPDIR”] (e.g. f”{env[“TMPDIR”]}/{tmpdir}”)

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a practical difference? Doesn't the current flow always create the tmpdir passed to this function under $TMPDIR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@d3dave current approach:
if tmpdir is set - mkdir it (w/o parents). propagate it to the child.
suggested approach:
if tmpdir is set - mkdir "$TMPDIR/tmpdir“. propagate it to the child.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, but the tmpdir arg, whenever it is passed it is always Path(os.environ["TMPDIR"]) / ("pyperf_" + random_prefix()) which is under $TMPDIR. So there is no difference because with both approaches the tmpdir is created under $TMPDIR.

Copy link
Contributor Author

@roi-granulate roi-granulate Sep 24, 2024

Choose a reason for hiding this comment

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

there’s no practical differences… I raised this to discuss what’s the better approach

@roi-granulate roi-granulate merged commit 72b7c70 into master Sep 26, 2024
@roi-granulate roi-granulate deleted the pyperf-tmpdir branch September 26, 2024 15:02
prashantbytesyntax pushed a commit to pinterest/gprofiler that referenced this pull request Jul 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants