`profiling.sampling` in `--binary` mode raises a `UnicodeEncodeError` while collecting the samples
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
Start with Lib/profiling/sampling/binary_collector.py, where the traceback shows the failing write, and inspect how sample stack frame strings are encoded. Reproduce with the xarray documentation profiling command on Python 3.15.1; done means binary mode collects samples without raising UnicodeEncodeError for the reported surrogate character.
由索引模型根據 Issue 內容生成。
描述
Bug report
when trying to profile building xarray's docs with profiling.sampling I get a UnicodeEncodeError while collecting the result.
For now, the command to reproduce is:
git clone https://github.com/pydata/xarray
cd xarray
pixi run -e doc python -m profiling.sampling run --binary -o profile.bin -m sphinx -b html -d _build/doctrees . _build/html
And the traceback is:
Traceback (most recent call last):
File "<frozen runpy>", line 201, in _run_module_as_main
File "<frozen runpy>", line 87, in _run_code
File ".../xarray/.pixi/envs/doc/lib/python3.15/profiling/sampling/__main__.py", line 65, in <module>
main()
~~~~^^
File ".../xarray/.pixi/envs/doc/lib/python3.15/profiling/sampling/cli.py", line 1011, in main
_main()
~~~~~^^
File ".../xarray/.pixi/envs/doc/lib/python3.15/profiling/sampling/cli.py", line 1167, in _main
handler(args)
~~~~~~~^^^^^^
File ".../xarray/.pixi/envs/doc/lib/python3.15/profiling/sampling/cli.py", line 1316, in _handle_run
collector = sample(
process.pid,
...<9 lines>...
blocking=args.blocking,
)
File ".../xarray/.pixi/envs/doc/lib/python3.15/profiling/sampling/sample.py", line 535, in sample
profiler.sample(collector, duration_sec, async_aware=async_aware)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../xarray/.pixi/envs/doc/lib/python3.15/profiling/sampling/sample.py", line 192, in sample
raise e from None
File ".../xarray/.pixi/envs/doc/lib/python3.15/profiling/sampling/sample.py", line 180, in sample
collector.collect(stack_frames)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File ".../xarray/.pixi/envs/doc/lib/python3.15/profiling/sampling/binary_collector.py", line 112, in collect
self._writer.write_sample(stack_frames, timestamp_us)
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'utf-8' codec can't encode character '\uddd0' in position 240: surrogates not allowed
I'm fully aware that this isn't a very minimal reproducer, but I didn't manage to find a minimal example as everything else I tried does not fail.
If you need more information or have any ideas on how to narrow this down I'd be happy to help.
versions:
python: 3.15.1 (conda-forge, linux-64)
sphinx: 9.2.0
(for a full env see https://github.com/pydata/xarray/actions/runs/40041611450/job/120713798864#step:3:1830 (lines 1830-2055))
CPython versions tested on:
3.15
Operating systems tested on:
Linux
Linked PRs
- gh-160615
- 主要語言
- Python
- 星號
- 77.7k
- 分支
- 38.3k
- 平均合併
- 14 小時 29 分鐘
- 30 天內合併 PR
- 699
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
python/cpython 的其他 Issue
-
topic-socket type-bug
難度 2/5 1-3 小時 新手友好度 72/100
python/cpython#160561 · 7 則留言 ·
維護者通常 1 天內回覆
-
tests topic-profiling type-bug
難度 2/5 1-3 小時 新手友好度 78/100
python/cpython#160334 · 1 則留言 ·
維護者通常 1 天內回覆
-
extension-modules type-bug
難度 2/5 1-3 小時 新手友好度 84/100
維護者通常 1 天內回覆
-
interpreter-core type-feature
難度 1/5 1 小時以內 新手友好度 78/100
python/cpython#160109 · 1 則留言 ·
維護者通常 1 天內回覆
-
extension-modules type-bug
難度 2/5 1-3 小時 新手友好度 72/100
python/cpython#160001 · 3 則留言 ·
維護者通常 1 天內回覆
相似的 Issue
-
The changelog workflow excludes otelbot but not dependabot, so every Dependabot pull request fails the changelog check可能已有人在做 @ocelotl 今天認領。 未關閉
難度 1/5 1 小時以內 新手友好度 82/100
open-telemetry/opentelemetry-python#5825 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
cuga-project/cuga-agent#1020 ·
維護者通常 2 天內回覆
-
難度 1/5 1 小時以內 新手友好度 70/100
microsoft/playwright#43640 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 84/100
stac-utils/stac-fastapi-elasticsearch-opensearch#965 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 70/100
維護者通常 1 天內回覆