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

py-spy loses the exit code of the original process #717

Open
tomtseng opened this issue Oct 31, 2024 · 0 comments
Open

py-spy loses the exit code of the original process #717

tomtseng opened this issue Oct 31, 2024 · 0 comments

Comments

@tomtseng
Copy link

tomtseng commented Oct 31, 2024

Suppose I have a python program program.py that exits with sys.exit(1) or by raising an exception. If I run py-spy record -- python program.py, this gives an exit code of 0. There's clearly a way in which this makes sense — the profile was correctly written, and if I had profiled the program with --pid then I would expect an exit code of 0 from py-spy even if the Python program had errored. But still, in this case of running without --pid, I would like some way to see the exit code of the Python program (e.g., by having it written to a file).

Is there some way of getting the exit code that I've overlooked? A roundabout way I can think of is to write a wrapper script that runs program.py as a subprocess and writes the exit code somewhere, and then I could run py-spy record --subprocesses on the wrapper.

(My use case here: I'm using py-spy to profile jobs on Kubernetes — in fact, py-spy is low enough overhead that I wanted to make every job I launch for my project to go through py-spy. I cannot use --pid because the pod security settings of my Kubernetes cluster do not allow me to add the SYS_PTRACE capability, so I run something like py-spy record -- python program.py in my jobs. But this means that if my programs error, the exit code is still 0 and the Kubernetes job is not marked as errored.)

Versions

  • Ubuntu 22.04
  • py-spy 0.3.14
  • python 3.10.14

And this issue still holds for this other combination of versions:

  • MacOS 15.0.1
  • py-spy 0.3.14, or built from main
  • python 3.11.4
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