Title: profiling: --collapsed export fails with UnicodeEncodeError on non-ASCII frame names · Issue #156810 · python/cpython · GitHub
Open Graph Title: profiling: --collapsed export fails with UnicodeEncodeError on non-ASCII frame names · Issue #156810 · python/cpython
X Title: profiling: --collapsed export fails with UnicodeEncodeError on non-ASCII frame names · Issue #156810 · python/cpython
Description: 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.expor...
Open Graph Description: 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 modu...
X Description: 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...
Opengraph URL: https://github.com/python/cpython/issues/156810
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"profiling: --collapsed export fails with UnicodeEncodeError on non-ASCII frame names","articleBody":"# Bug report\n\n### Bug description:\n\n`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:\n\n```\nUnicodeEncodeError: 'ascii' codec can't encode characters ...\nUnicodeEncodeError: 'utf-8' codec can't encode character '\\udc80' ... surrogates not allowed\n```\n\nNon-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.\n\n### CPython versions tested on:\n\nCPython main\n\n### Operating systems tested on:\n\nLinux, macOS\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-156811\n* gh-156814\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/tonghuaroot","@type":"Person","name":"tonghuaroot"},"datePublished":"2026-09-02T09:27:36Z","url":"https://github.com/python/cpython/issues/156810"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f706189d-551a-de25-06cc-936c7f751b48 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E556:2E3FEE:415627F:52A834D:6B021BB3 |
| html-safe-nonce | 28e10dd5934d155efbd457b0baa6fffd6aeb0cd2fd3716b0d89e12178a5fe427 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNTU2OjJFM0ZFRTo0MTU2MjdGOjUyQTgzNEQ6NkIwMjFCQjMiLCJ2aXNpdG9yX2lkIjoiODg5OTgwNTYzMDgxOTM0MzI4MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c878df45b6300c57eeefe7d281e38f7f796381545cf3d217e39f5f1a93b5fe98 |
| hovercard-subject-tag | issue:5322163737 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/156810/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c53f82c08a6bfa639c13a35b41956d53c5c250cb8850bf763aed1bffafe18fc5/python/cpython/issues/156810 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c53f82c08a6bfa639c13a35b41956d53c5c250cb8850bf763aed1bffafe18fc5/python/cpython/issues/156810 |
| og:image:alt | 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 modu... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tonghuaroot |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width