Add `name` parameter to a `SharedMemoryManager.ShareableList` method

未关闭 适合新手
#96,215 0 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
60/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
停滞
技术栈
python

调研方向

从 Lib/multiprocessing/managers.py 文件底部附近的 SharedMemoryManager.ShareableList 方法开始,然后将其与 shared_memory.ShareableList 的 name 参数进行比较。完成的标准是 manager 方法接受并传递 name,同时保留其跟踪和清理行为。

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

描述

stdlib type-feature

Feature or enhancement

I would like to pass a name for shared list from SharedMemoryManager but I apparently cannot do this.

with SharedMemoryManager() as smm:
    my_shared_list = smm.ShareableList(sequence=range(10),name="special name")
    pass

What I get:

my_shared_list = smm.ShareableList(sequence=range(10),name="special name")
TypeError: SharedMemoryManager.ShareableList() got an unexpected keyword argument 'name'

Possible solution

Just change method ShareableList in the bottom of this source file to following:

        def ShareableList(self, sequence, name=None):
            """Returns a new ShareableList instance populated with the values
            from the input sequence, to be tracked by the manager."""
            with self._Client(self._address, authkey=self._authkey) as conn:
                sl = shared_memory.ShareableList(sequence=sequence,name=name)
                try:
                    dispatch(conn, None, 'track_segment', (sl.shm.name,))
                except BaseException as e:
                    sl.shm.unlink()
                    raise e
            return sl

I wonder

Why this feature is not implemented from the very beggining?

主要语言
Python
星标
77.2k
派生
36k
平均合并
1 天 9 小时
30 天内合并 PR
558

贡献指南

打开贡献指南

从这里开始

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

python/cpython 的其他 Issue

查看 python/cpython 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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