Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Prevent --browser from opening when no report is generated #145306

Copy link
Copy link
@misa-j

Description

@misa-j
Issue body actions

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 --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.py
print("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')

I can open a PR with a proposed fix

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    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
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.