Expected python bug using multiprocessing and inheritance

未關閉
#96,469 2 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
python

研究方向

首先在 Python 3.9.12 上執行提供的 reproducer,並追蹤 multiprocessing 在子程序中如何處理繫結的 super().process 目標。將其與明確的 A.process 目標進行比較;當超類別呼叫不再遞迴,同時保留預期的 multiprocessing 行為時,即視為完成。

由索引模型根據 Issue 內容生成。

描述

stdlib type-bug

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

主要語言
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 摘要。