Mixed inheritance between slotted and non slotted classes leads to issues with parallelisation.
维护者通常 2 天内回复
评估
调研方向
Start with the provided mixed-inheritance reproducer and inspect how the Child instance is copied for multiprocessing, particularly the interaction between dict and slots. The work is done when the copied object retains z and name and the pool example succeeds, with regression coverage for the failing case.
由索引模型根据 Issue 内容生成。
描述
Mixed inheritance between slotted and non-slotted classes seems to lead to some issues when object are copied for parallelization.
The following code example does not work and raises: AttributeError: 'Child' object has no attribute 'z'
import attrs
import multiprocessing as mp
@attrs.define(slots=False, kw_only=True)
class Parent:
name: str
@attrs.define
class Child(Parent):
x: float
def __attrs_post_init__(self):
self.z = self.x + 2
def arg_plus_z(self, arg):
return self.z + arg
test = Child(3, name = "as")
with mp.Pool(processes=4) as pool:
result = pool.map(test.arg_plus_z, range(100))
whilst adding slots=False to the child class or registering z using z: float = attrs.field(default = None, init=False) does work:
import attrs
import multiprocessing as mp
@attrs.define(slots=False, kw_only=True)
class Parent:
name: str
@attrs.define(slots=False)
class Child(Parent):
x: float
def __attrs_post_init__(self):
self.z = self.x + 2
def arg_plus_z(self, arg):
return self.z + arg
test = Child(3, name = "as")
with mp.Pool(processes=4) as pool:
result = pool.map(test.arg_plus_z, range(100))
It seems like the object copy of test passed to each one of the processes does not copy the __dict__ (which includes z and name) but only the __slots__.
I know that according to the attrs documentation mixed inheritance between slotted and non slotted classes is considered a bad practice. I stumbled across this by accident and it might also be more of a missing feature than a bug.
Meta:
- attrs-version: '21.4.0'
- python-version: '3.9.13'
- 主要语言
- Python
- 星标
- 5.9k
- 派生
- 503
- 平均合并
- 4 天 18 小时
- 30 天内合并 PR
- 5
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python-attrs/attrs 的其他 Issue
-
Docs: `attrs.filters` is missing stated examples可能已有人在做 @feiiiiii5 于 24 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
python-attrs/attrs#1627 ·
维护者通常 2 天内回复
-
slots declared on attrs-decorated class are ignored/lost可能已有人在做 @anshurajbisoyi98-ctrl 于 16 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 68/100
python-attrs/attrs#1637 ·
维护者通常 2 天内回复
-
难度 5/5 一周以上 新手友好度 20/100
python-attrs/attrs#1620 ·
维护者通常 2 天内回复
-
Incorrect annotation for forward reference in generated constructor可能已有人在做 @MohammedAnasNathani 于 81 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 55/100
python-attrs/attrs#1596 · 2 条评论 · 2 个 reaction ·
维护者通常 2 天内回复
-
Decorated functions do not work with inheritance可能已有人在做 @sb123sb123 于 28 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 35/100
python-attrs/attrs#1549 · 3 条评论 ·
维护者通常 2 天内回复
查看 python-attrs/attrs 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 77/100
mihai-vlc/sublime-jsfmt#56 ·
-
comp/cli comp/plugins P2 type/bug
难度 2/5 1-3 小时 新手友好度 75/100
NousResearch/hermes-agent#141917 · 1 条评论 ·
维护者通常 1 天内回复
-
Go device SDK: Whisper transcriber keeps buffering and transcribing audio appended after Stop()可能已有人在做 @apoorvdarshan 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
BasedHardware/omi#22770 ·
维护者通常 1 天内回复
-
bug needs-acceptance wg/router-models-inference-runtime
难度 2/5 1-3 小时 新手友好度 66/100
vllm-project/semantic-router#5295 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
huggingface/huggingface_hub#5210 ·
维护者通常 1 天内回复