py-spy: Doesn't work on OSX
Started python interpreter
>>> import sys
>>> sys.version
'3.7.7 (v3.7.7:d7c567b08f, Mar 10 2020, 02:56:16) \n[Clang 6.0 (clang-600.0.57)]'
>>> sys.executable
'/Library/Frameworks/Python.framework/Versions/3.7/bin/python3'
>>> import os
>>> os.getpid()
62993
Trying to attach profiler
Mac-mini:~ konstantin$ sudo py-spy dump --pid 62993
Error: Failed to open process - check if it is running.
Reason: Undefined error: 0 (os error 0)
Mac-mini:~ konstantin$ sudo py-spy record -o test.svg --pid 62993
Error: Failed to open process - check if it is running.
Reason: Operation timed out (os error 60)
Mac-mini:~ konstantin$ py-spy -V
py-spy 0.3.3
OSX version: 10.15.3 (19D76)
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 7
- Comments: 16 (2 by maintainers)
I think this might be a change with SIP (system integrity protection) on the latest version of OSX - where SIP prevents us from attaching to programs in /Library/Frameworks/ as well as in /usr/bin (https://github.com/benfred/py-spy#why-am-i-having-issues-profiling-usrbinpython-on-osx) . If so this might not be something we can fix - the only choices will be to use a different python (anaconda installs to a user directory instead of a system directory) or disable SIP
the same in virtualenv
My environment
Experienced with macOS Big Sur 11.2.3, disabling SIP and using a virtualenv did not resolve the issue.
Workaround found is to dockerize the python app to bypass macOS restrictions. This blog post proposes a nice walkthrough of a minimum reproducible example of using py-spy through
docker
/docker-compose
to monitor a python app.same here, the command actually starts running, but then stops abruptly.
macOS 14.4 py-spy 0.3.14
I got this today. One process works fine with py-spy, another not. The one I couldn’t look at was python 3.9.6, and then I tried with a 3.11 and that worked. Both installed via homebrew.
I’m having the same issue but noticed it was working fine with python3.6 and not with python3.8… Hopefully this can be of any help solving this issue