python / python/cpython

Expected python bug using multiprocessing and inheritance

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

还没有人认领这个 Issue。

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

描述

This is a bug report:

import time
import multiprocessing as mp
class A(object):
    def __init__(self, childnodes, **kwargs) -> None:
        self._childnodes = childnodes
        self._kwargs = kwargs

    def process(self, datablock, meta):
        print("Hello")
        time.sleep(1)
        print("world")

class B(A):
    def process(self, datablock, meta):
        print("before")
        mp.Process(target=super().process, args=(self, datablock, meta)).start()
        print("after")

if __name__ == "__main__":
    b = B([1,2,3])
    b.process([4,5,6], {'foo':42})

This seems to run forerever which is not expected. Reason seems to be that that somehow, super().process actually calls B.process instead of A.process in the subprocess. This is not expected behaviour. As additional evidence towards that, the program behaviour can be corrected by changing

mp.Process(target=super().process, args=(self, datablock, meta)).start()`meta)).start()

with

mp.Process(target=A.process, args=(self, datablock, meta)).start()

Machine:
MacBook Pro (16-inch, 2021)
MacOS Monteray 12.5
Chip: Apple M1 Max
Python version: 3.9.12

贡献指南

打开贡献指南

从这里开始

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

调研方向

首先在 Python 3.9.12 上运行提供的 reproducer,并跟踪 multiprocessing 在子进程中如何处理绑定的 super().process 目标。将其与显式的 A.process 目标进行比较;当超类调用不再递归,同时保留预期的 multiprocessing 行为时,即视为完成。

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

评估

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

把新 issue 发到你的邮箱

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