{"id":21795,"library":"pystack","title":"pystack","description":"pystack is a command-line tool developed by Bloomberg for analyzing the stack of remote Python processes. It attaches to a running Python process (supporting Python >=3.7) and dumps the Python stack frames, including local variables and source references, without requiring debug symbols or ptrace. The current version is 1.6.0, with a stable maintenance release cadence.","status":"active","version":"1.6.0","language":"python","source_language":"en","source_url":"https://github.com/bloomberg/pystack","tags":["stack-trace","remote-process","debugging","linux"],"install":[{"cmd":"pip install pystack","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"pystack is a command-line tool; the Python module is typically used via subprocess or CLI. Importing is valid but uncommon.","symbol":"pystack","correct":"import pystack"}],"quickstart":{"code":"import subprocess\nimport os\n\n# Attach to a Python process by PID (replace 1234)\nresult = subprocess.run(['pystack', '1234'], capture_output=True, text=True)\nprint(result.stdout)\n","lang":"python","description":"Run pystack via CLI from Python. The tool must be installed and the process must be a Python process >=3.7."},"warnings":[{"fix":"Ensure target process uses Python >=3.7. Use `pystack --version` to check compatible versions.","message":"pystack requires the target Python process to have a compatible version (>=3.7). Attaching to an older Python version will fail.","severity":"breaking","affected_versions":"<=1.6.0"},{"fix":"Verify target is a Python process and OS is Linux (official support). Use `file /proc/<pid>/exe` to check.","message":"Running pystack on a process that is not a Python process or on a non-Linux platform will produce confusing errors.","severity":"gotcha","affected_versions":"all"},{"fix":"Run as root or adjust ptrace settings: `echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope`","message":"pystack requires permissions to attach to a remote process (e.g., same user or ptrace scope). Without them, it fails silently or with 'No such process'.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Provide a valid integer process ID. Example: `pystack 1234`","cause":"Non-numeric PID argument passed to pystack CLI.","error":"pystack: error: argument PID: invalid integer value: 'abc'"},{"fix":"Verify the process exists: `ps aux | grep 1234`. Check permissions and ptrace settings.","cause":"The target PID does not exist or pystack cannot access it.","error":"pystack: Process 1234 not found"},{"fix":"Run as root or temporarily disable ptrace_scope: `echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope`","cause":"Insufficient permissions to attach to the process (e.g., ptrace restrictions).","error":"OSError: [Errno 1] Operation not permitted"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}