con un clic
flight-profiler-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.
// 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.
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.
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-reload |
| description | 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. |
Reload function implementation based on the latest file content without restarting the process. Enables live patching — edit the source file, then reload to apply the change immediately.
Prerequisites: Read the flight-profiler-attach skill first for platform requirements, installation, permissions, and connection details.
print() or logging statements into a function for auxiliary diagnostics — the output will appear in the target process's stdout/log. This is useful when you know where the process log is directed (e.g., a log file, container stdout, or a terminal). Note: reload is not limited to adding prints — it can change the actual execution logic of the method as wellflight_profiler <pid> --cmd "reload module [class] method [-v]" --no-color
module — the module name as it would be imported in the target process. For example, if the target code does from myapp.utils import helper, then module is myapp.utils. PyFlightProfiler locates the module via importlib.import_module. If you're unsure of the module name, run a separate command to resolve it first: flight_profiler <pid> --cmd "module /absolute/path/to/file.py" --no-color, then use the returned module name here.class (optional) — class name if method belongs to a classmethod — target method name| Flag | Description | Default |
|---|---|---|
-v, --verbose | Display the full method source after reload. Without -v, methods longer than 20 lines are truncated (first 10 + last 10 lines). | off |
Success — function was reloaded with new code:
Reload is done successfully.
Located file path: /path/to/file.py
Extracted method source:
def compute(x, y):
result = x + y
print(f"compute({x}, {y}) = {result}")
return result
No change — the source file has not been modified since the function was last loaded:
Error: Method source has not changed.
Located file path: /path/to/file.py
Extracted method source:
def compute(x, y):
return x + y
Error — module/method not found or other failure:
Error: Cannot locate method nonexistent in module __main__.
| Field | Description |
|---|---|
| Status line | "Reload is done successfully." or "Error: <reason>." |
Located file path | The source file path resolved from the module (shown when module is found) |
Extracted method source | The method source code read from the file (shown when method is located) |
If the file hasn't been edited since the function was loaded, reload reports no change:
flight_profiler <pid> --cmd "reload __main__ compute" --no-color
Error: Method source has not changed.
Located file path: /Users/zy/workspace/app/main.py
Extracted method source:
def compute(x, y):
return x + y
This is expected — edit the source file first, then reload.
After editing compute in the source file:
flight_profiler <pid> --cmd "reload __main__ compute -v" --no-color
Reload is done successfully.
Located file path: /Users/zy/workspace/app/main.py
Extracted method source:
def compute(x, y):
result = x + y
print(f"compute({x}, {y}) = {result}")
return result
After editing Calculator.add in the source file:
flight_profiler <pid> --cmd "reload __main__ Calculator add -v" --no-color
Reload is done successfully.
Located file path: /Users/zy/workspace/app/main.py
Extracted method source:
def add(self, a, b):
print(f"Calculator.add({a}, {b})")
return a + b
flight_profiler <pid> --cmd "reload __main__ nonexistent" --no-color
Error: Cannot locate method nonexistent in module __main__.
flight_profiler <pid> --cmd "reload nonexistent_module func" --no-color
Error: Unexpected error during reload: No module named 'nonexistent_module'.
The simplest cycle is: edit source → reload → observe the effect. If the method is on a regularly triggered call path (e.g., handling HTTP requests), you'll see the change take effect immediately after reload.
For deeper investigation — such as observing internal method arguments, return values, or call trees — use watch/trace before and after reload:
# Optional: use watch/trace to inspect internal behavior before the fix
flight_profiler <pid> --cmd "watch __main__ compute -n 3" --no-color
# Step 1: Edit the source file to fix the issue
# (use Edit tool to modify the function)
# Step 2: Apply the fix live and verify the new source
flight_profiler <pid> --cmd "reload __main__ compute -v" --no-color
# Optional: use watch/trace to verify internal behavior after the fix
flight_profiler <pid> --cmd "watch __main__ compute -n 3" --no-color
If you edited multiple methods in one fix, reload each method separately:
# Reload each modified method individually
flight_profiler <pid> --cmd "reload __main__ Calculator validate -v" --no-color
flight_profiler <pid> --cmd "reload __main__ Calculator process -v" --no-color
flight_profiler <pid> --cmd "reload __main__ helper_func -v" --no-color
import statements — must be placed inside the function. Python supports function-level imports, so move them into the body:# WRONG — module-level import is outside the function body, reload ignores it
import json
def process(data):
return json.dumps(data)
# CORRECT — import inside the function body, reload picks it up
def process(data):
import json
return json.dumps(data)
-v to verify the reloaded source matches what you expect-v to see the full source.flight_profiler/plugins/reload/cli_plugin_reload.pyflight_profiler/plugins/reload/reload_parser.pyflight_profiler/plugins/reload/server_plugin_reload.py