python / python/cpython

ShareableList removes trailing zeroes from strings and bytes

未关闭
#96,779 1 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

topic-multiprocessing type-bug
主要语言
Python
星标
77.2k
派生
36k
PR 合并指标
PR 指标待抓取

描述

Bug report

from multiprocessing.shared_memory import ShareableList
s, b = '\x00\x01\x00', bytes([0,1,0])
sl = ShareableList([s, b])
s == sl[0], b == sl[1]

gives (False, False) because the trailing zeroes get lost in the ShareableList: sl holds ShareableList(['\x00\x01', b'\x00\x01'], name='wnsm_...'). I would expect that strings and bytes keep the trailing zeroes also when added to a ShareableList.

Your environment

  • CPython versions tested on: 3.8.5, 3.10.6
  • Operating system and architecture: Windows 10, 64bit

Analysis

There are three places in class ShareableList in Lib/multiprocessing/shared_memory.py, where trailing zeroes are explicitely removed: ...rstrip(b'\x00').... For what reason?

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 Lib/multiprocessing/shared_memory.py 开始,检查使用 rstrip(b'\x00') 的三个 ShareableList 位置;复现所提供的示例以确认该行为。完成的标准是字符串和 bytes 保留末尾的零,同时现有的 ShareableList 行为保持不变,并在项目中该入口点对应的测试所在位置添加回归覆盖。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
operating-systems
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
描述清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。