When profiling a script that does not produce HTML output, the following warning is displayed:
Warning: No functions found in profiling data. Check if sampling captured any data.
However, when the --browser option is specified, the program still attempts to open the output file in a browser.
./python -m profiling.sampling run --flamegraph --browser script.py
# script.pyprint("hello world")
Suggested Fix
diff --git a/Lib/profiling/sampling/cli.py b/Lib/profiling/sampling/cli.py
index f4b31aad45b..75a21429705 100644
--- a/Lib/profiling/sampling/cli.py+++ b/Lib/profiling/sampling/cli.py@@ -607,6 +607,10 @@ def _open_in_browser(path):
"""
abs_path = os.path.abspath(path)
+ if not os.path.exists(abs_path):+ print(f"Warning: Could not find {abs_path}", file=sys.stderr)+ return+
# For heatmap directories, open the index.html file
if os.path.isdir(abs_path):
index_path = os.path.join(abs_path, 'index.html')
Thanks for the report, something like this sound sensible.
We already get a warning:
hello world
Captured 1 samples in 0.00 seconds
Sample rate: 877.29 samples/sec
Error rate: 100.00
Flamegraph data: 0 root functions, total samples: 0, 1 unique strings
Warning: No functions found in profiling data. Check if sampling captured any data.
Rather than checking if the file exists and printing another warning, perhaps we could have export return a success/fail code?
Activity
hugovk commented on Feb 27, 2026
Thanks for the report, something like this sound sensible.
We already get a warning:
Rather than checking if the file exists and printing another warning, perhaps we could have export return a success/fail code?
cpython/Lib/profiling/sampling/cli.py
Lines 663 to 667 in 11eec7a
cpython/Lib/profiling/sampling/cli.py
Lines 1206 to 1210 in 11eec7a
Here's one of them, we'd have to check if it makes sense for the others:
cpython/Lib/profiling/sampling/stack_collector.py
Lines 152 to 156 in 11eec7a
cc @pablogsal
pythongh-145306: gate --browser on export success
pythongh-145306: gate --browser on export success
pythongh-145306: keep a single regression test
pythongh-145306: keep a single regression test
Merge branch 'main' into pythongh-145306-browser-export-success
misa-j commented on Feb 28, 2026
Yes I agree with this approach. Printing another warning feels redundant here.
gh-145306: Fix browser open after empty export (#150017)
[3.15] gh-145306: Fix browser open after empty export (GH-150017) (#1…