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.
日本語の概要は準備中です。原文の説明を表示しています。
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 --timeout <seconds>
<pid> — target process PID--cmd — single-shot mode (run one command and exit, no interactive REPL)--no-color — disable ANSI colors for clean text output--timeout — stop after N seconds and exit with code 124--timeout for streaming commandswatch, trace, tt and gilstat print a record each time the observed code
runs, and they only return once their display limit (-n) is reached. If the
function is never called — wrong module, idle service, wrong worker process —
the command blocks forever and your session hangs.
Pass a deadline that matches how often you expect the code to run:
# A busy request handler: a few seconds is plenty
flight_profiler <pid> --cmd "watch --pkg app.api --func handle -n 3" --no-color --timeout 15
# A background job that runs every minute
flight_profiler <pid> --cmd "watch --pkg app.jobs --func sync -n 1" --no-color --timeout 90
Exit code 124 means the deadline was reached. That is a normal outcome, not a
crash: it tells you the function was not called during the window. When you see
it, report that no invocation was observed and consider whether you targeted the
right process (see "Multi-process architecture" above) or the right module.
Never kill the client to escape a hanging command. watch and trace
install instrumentation inside the target process, and the client removes it on
exit. --timeout and Ctrl-C both take that clean path; kill -9 leaves the
instrumentation running in production.
Point-in-time commands (stack, getglobal, module, vmtool) return
immediately, so a deadline is optional there — though a small one is still good
practice in case the target process is stuck holding the GIL.
flight_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:
まだレビューはありません。使ってみた感想をお寄せください。
概要と使いどころ
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.
日本語の概要は準備中です。原文の説明を表示しています。