ShareableList removes trailing zeroes from strings and bytes

Open
#96,779 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python

Research direction

Start in Lib/multiprocessing/shared_memory.py and inspect the three ShareableList locations using rstrip(b'\x00'); reproduce the supplied example to confirm the behavior. Done means strings and bytes retain trailing zeroes while existing ShareableList behavior remains intact, with regression coverage added where the project’s tests for this entry point belong.

Written by the indexing model from the issue text.

Description

topic-multiprocessing type-bug

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?

Dominant language
Python
Stars
77.2k
Forks
36k
Avg merge
1d 9h
Merged PRs (30d)
558

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python/cpython

All issues in python/cpython

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.