بنقرة واحدة
flight-profiler-attach
// Prerequisites and connection details for attaching to a live Python process with PyFlightProfiler. Read this skill first before using any other PyFlightProfiler command (watch, trace, stack, perf, etc.).
// Prerequisites and connection details for attaching to a live Python process with PyFlightProfiler. Read this skill first before using any other PyFlightProfiler command (watch, trace, stack, perf, etc.).
Inspect Python module global field or class static field value in a running Python process. Use this for safe, read-only inspection of global variables, configuration objects, or class-level state.
Translate a file path to its Python module name in a running Python process. Use this when you know a file path but need the module name for commands like watch, trace, or reload.
Hot-reload a Python function implementation from the latest file content without restarting the process. Use this to apply code fixes live after identifying a bug with watch/trace.
Inspect stack frames of a running Python process including thread stacks, native C-level frames, and async coroutine stacks. Use this to see what each thread is currently doing and diagnose hangs, deadlocks, or stuck async tasks.
Trace execution time of Python method invocations in a live process with call stack visualization. Use this to see a hierarchical call tree showing which sub-calls are slow and where time is spent within a function.
Inspect live Python class instances in a running process — find all instances of a class, examine their attributes/state, or invoke methods on them. Also supports forcing GC. Use this when you need to probe object-level runtime state beyond what watch/getglobal can provide.
| name | flight-profiler-attach |
| description | Prerequisites and connection details for attaching to a live Python process with PyFlightProfiler. Read this skill first before using any other PyFlightProfiler command (watch, trace, stack, perf, etc.). |
All PyFlightProfiler commands require attaching to a running Python process. This skill covers the prerequisites, how to connect, and how to troubleshoot failures.
PyFlightProfiler skills are designed for live process diagnostics. When using these skills, you should combine two sources of information:
stack, watch, trace to observe actual runtime behavior: what threads are active, what methods are being called, what arguments are passed, and how long they take.Always leverage both: read the code to know what to look for, then use PyFlightProfiler to see what's actually happening at runtime.
Before using any PyFlightProfiler command, verify these conditions in order. If any check fails, PyFlightProfiler cannot be used — report the failure reason to the user.
uname -s should return Linux or Darwinldd --version | head -1cat /proc/sys/kernel/yama/ptrace_scope — value should be 0 (or the process must be run as root). On CPython >= 3.14, sys.remote_exec is used instead of ptrace.sys.remote_exec is used instead.flight_profiler must be installed in the exact same Python/pip environment as the target process. This means the flight_profiler CLI and the target process must share the same Python interpreter and site-packages. After injection, the agent runs inside the target process and imports flight_profiler modules — if the package isn't in the target's sys.path, the import will fail.
Example: if the target process runs under /Users/zy/miniforge3/envs/py310/bin/python, then:
/Users/zy/miniforge3/envs/py310/bin/pip3 install flight_profiler/Users/zy/miniforge3/envs/py310/bin/flight_profiler <pid>Using a flight_profiler from a different environment (e.g., system Python or another conda env) will cause the injection to fail because the target process cannot find the flight_profiler package in its own sys.path.
# Step 1: Find the target process's Python executable
ls -l /proc/<pid>/exe # Linux
ps -p <pid> -o command= # macOS
# Step 2: Check if flight_profiler is already installed in that environment
/path/to/target/python -m pip show flight_profiler
# Step 3: If not installed, install it using the target's pip
/path/to/target/python -m pip install flight_profiler
# Step 4: Run flight_profiler using the same environment's binary
/path/to/target/bin/flight_profiler <pid>
Common scenario — conda / virtualenv:
# If the target runs under /Users/zy/miniforge3/envs/py310
# Option A: activate the environment, then install and run
conda activate py310
pip3 install flight_profiler
flight_profiler <pid>
# Option B: use the full path directly (no activation needed)
/Users/zy/miniforge3/envs/py310/bin/pip3 install flight_profiler
/Users/zy/miniforge3/envs/py310/bin/flight_profiler <pid>
The flight_profiler process must have permission to attach to the target:
sudo flight_profiler <pid> ...CAP_SYS_PTRACE capability can substitute for root# Check target process owner
ps -p <pid> -o user=
# If target is root-owned
sudo flight_profiler <pid> --cmd "stack" --no-color
If the above prerequisites cannot be satisfied, print the specific failure reason and inform the user that PyFlightProfiler skills cannot be used for this target process. Common failure messages:
If the user gives a PID number, use it directly — this is the most straightforward case. Skip to "Run a command" below.
If the user provides a file path, script name, or process name, search for matching Python processes:
# Search by script name or file path
pgrep -af "my_script.py"
pgrep -af "myapp"
# List all Python processes with full command lines
ps aux | grep python
# Search by a keyword in the command line
ps aux | grep -E "gunicorn|uvicorn|celery|your_app"
Filter out processes that are obviously in a different Python/pip environment (e.g., different conda env, different virtualenv path) — they won't work with flight_profiler even if found.
Many Python applications use multi-process architectures (e.g., multiprocessing, gunicorn workers, ML inference frameworks like vLLM/TGI with separate launcher and worker processes). The method you want to observe typically runs in a child worker process, not the launcher/master process.
# List the process tree to see parent-child relationships
pstree -p <launcher_pid>
# Or find all child processes
ps --ppid <launcher_pid> -o pid,cmd # Linux
ps -o pid,ppid,command | grep <launcher_pid> # macOS
How to decide which PID to use:
stack to identify the right processWhen multiple Python processes exist and you cannot determine which one contains the target code, use the stack command to inspect candidate processes. Look for common file path prefixes or recognizable module names in the stack frames:
# Check what each candidate process is running
flight_profiler <pid_1> --cmd "stack" --no-color
flight_profiler <pid_2> --cmd "stack" --no-color
The stack output lists all active Python files and functions per thread. Compare the file paths against the user's project directory or the file they mentioned — the process whose stack frames reference the same codebase is the target.
Tip: if the user mentioned a specific file (e.g., app/handlers/user.py), look for that path or its module equivalent in the stack output to confirm the process.
All commands use this format:
flight_profiler <pid> --cmd "<command>" --no-color
<pid> — target process PID--cmd — single-shot mode (run one command and exit, no interactive REPL)--no-color — disable ANSI colors for clean text outputflight_profiler checks if the agent server is already injected (scans ports 16000-16500)profiler_agent.py into the target process via ptrace/LLDB/sys.remote_exec--cmd calls reuse the existing agent — no re-injection, fast (< 1s)# Custom port range
PYFLIGHT_INJECT_START_PORT=20000 PYFLIGHT_INJECT_END_PORT=20500 flight_profiler <pid> --cmd "stack" --no-color
# Custom timeout
PYFLIGHT_INJECT_TIMEOUT=10 flight_profiler <pid> --cmd "stack" --no-color
Add --debug to see detailed diagnostic output:
flight_profiler <pid> --cmd "stack" --no-color --debug
This prints: