GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — profiling: --collapsed export fails with UnicodeEncodeError on non-ASCII frame names · Issue #156810 · python/cpython

profiling: --collapsed export fails with UnicodeEncodeError on non-ASCII frame names #156810

New issue
Copy link
New issue
Copy link
Closed
Closed
profiling: --collapsed export fails with UnicodeEncodeError on non-ASCII frame names#156810
Copy link
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

@tonghuaroot
tonghuaroot
opened on Sep 2, 2026
Issue body actions

Bug report

Bug description:

CollapsedStackCollector.export (Lib/profiling/sampling/stack_collector.py) opens its output with open(filename, "w") — no encoding=. It is the only exporter in that module missing it; FlamegraphCollector.export, the JSONL exporter and the heatmap exporter all pass encoding="utf-8". Because the collapsed format writes frame names verbatim (the JSON exporters escape non-ASCII via ensure_ascii), --collapsed export raises UnicodeEncodeError when a sampled frame's function or file name contains non-ASCII characters under a non-UTF-8 locale, or surrogate-escaped characters (from an undecodable path) on any locale:

UnicodeEncodeError: 'ascii' codec can't encode characters ...
UnicodeEncodeError: 'utf-8' codec can't encode character '\udc80' ... surrogates not allowed

Non-English identifiers are common and non-UTF-8 locales are supported, so profiling such a program with --collapsed produces no output and an uncaught error.

CPython versions tested on:

CPython main

Operating systems tested on:

Linux, macOS

Linked PRs

  • gh-156810: Write the profiler's collapsed-stack export as UTF-8 #156811
  • [3.15] gh-156810: Write the profiler's collapsed-stack export as UTF-8 (GH-156811) #156814

Activity

  1. pablogsal
    added a commit that references this issue on Sep 2, 2026

    gh-156810: Write the profiler's collapsed-stack export as UTF-8 (#156811

    c3706f4
  2. aisk
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    topic-profiling
    on Sep 2, 2026
  3. tonghuaroot
    changed the title [-]profiling: --collapsed export crashes with UnicodeEncodeError on non-ASCII frame names[/-] [+]profiling: --collapsed export fails with UnicodeEncodeError on non-ASCII frame names[/+] on Sep 8, 2026
  4. clin1234
    added a commit that references this issue on Sep 12, 2026

    pythongh-156810: Write the profiler's collapsed-stack export as UTF-8 (…

    62c2b5e
  5. pablogsal
    added 2 commits that reference this issue on Oct 5, 2026

    [3.15] gh-156810: Write the profiler's collapsed-stack export as UTF-8 (

    fce28da

    Revert "[3.15] pythongh-156810: Write the profiler's collapsed-stack …

    da8b9ac
  6. hugovk
    closed this as completedon Oct 11, 2026
  7. pablogsal
    added a commit that references this issue on Oct 11, 2026

    [3.15] Restore deferred backports for 3.15.1, including GH-158874 (#1…

    4ceb3fa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.