Repository navigation
Prevent --browser from opening when no report is generated #145306
Copy link
Copy link
Closed
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-profilingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Feb 27, 2026 - addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Feb 27, 2026 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
exportreturn a success/fail code?cpython/Lib/profiling/sampling/cli.py
Lines 663 to 667 in 11eec7a
collector.export(filename) # Auto-open browser for HTML output if --browser flag is set if args.format in ('flamegraph', 'heatmap') and getattr(args, 'browser', False): _open_in_browser(filename) cpython/Lib/profiling/sampling/cli.py
Lines 1206 to 1210 in 11eec7a
collector.export(filename) # Auto-open browser for HTML output if --browser flag is set if args.format in ('flamegraph', 'heatmap') and getattr(args, 'browser', False): _open_in_browser(filename) 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
if num_functions == 0: print( "Warning: No functions found in profiling data. Check if sampling captured any data." ) return cc @pablogsal
- added 5 commits that reference this issue
on Feb 28, 2026 Yes I agree with this approach. Printing another warning feels redundant here.
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-profilingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Bug report
Bug description:
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
--browseroption is specified, the program still attempts to open the output file in a browser.Suggested Fix
I can open a PR with a proposed fix
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs