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

Handling paths set by shell environment variables #674

Open
aditya-sengupta opened this issue Aug 7, 2024 · 0 comments
Open

Handling paths set by shell environment variables #674

aditya-sengupta opened this issue Aug 7, 2024 · 0 comments

Comments

@aditya-sengupta
Copy link

aditya-sengupta commented Aug 7, 2024

I'm trying to profile code that uses paths set by environment variables within zsh. Within py-spy these paths all return None.

MWE: in test_pyspy.py,

import os
import numpy as np
import time

np.load(os.path.join(os.environ.get("pyspy_testpath"), "test.npy"))
time.sleep(5) # to give profiling time to collect samples

With the existence of pyspy_testpath set by export pyspy_testpath="/Users/adityasengupta/projects/misc" and the existence of test.npy at that path, python3 test_pyspy.py runs as expected. But py-spy has the following output:

>>> sudo py-spy record -- python3 test_pyspy.py                                    
py-spy> Sampling process 100 times a second. Press Control-C to exit.

Traceback (most recent call last):
  File "/Users/adityasengupta/projects/misc/test_pyspy.py", line 5, in <module>
    np.load(os.path.join(os.environ.get("pyspy_testpath"), "test.npy"))
  File "/opt/homebrew/Cellar/[email protected]/3.10.14_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/posixpath.py", line 76, in join
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType

py-spy> Stopped sampling because process exited
py-spy> Wrote flamegraph data to 'python3-2024-08-07T14:29:49-07:00.svg'. Samples: 19 Errors: 0
python3-2024-08-07T14:29:49-07:00.svg?                                                                                                                     
[0]     cancel
[1]     Open the file python3-2024-08-07T14:29:49-07:00.svg
[2]     Open the URL  python3-2024-08-07T14:29:49-07:00.svg

Which did you mean? Cancelled.

It's not feasible to rewrite the code to avoid these references as it's a large package, is there a workaround for this?

Using py-spy 0.3.14, Python 3.10.14 on a MacBook M1 Pro running MacOS Ventura 13.2.1.

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

No branches or pull requests

1 participant