python / python/cpython

`_pickle.PicklingError` on 3.14.0a1+ where it didn't before due to the start method change from fork to forkserver

未關閉
#125,714 11 則留言 0 個 reaction 已指派 1 人 在 GitHub 檢視

@gpshead 已經在處理了。

開始於 2024年11月14日。

3.14 docs stdlib topic-multiprocessing type-bug
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

Bug report

Bug description:

Code dating back to Python 2 had to do super(OwnClassName, self) instead of super(). Modules designed to be reloadable could not use the super(OwnClassName, self) syntax in their non-constructor method, as OwnClassName was re-binded to the class of the new module, rather than the class that had the name when the object was constructed (which differs when the object was constructed before a reload). Therefore, such modules defined classes like this:

class Subclass(Superclass):
    def __init__(self):
        self.__parent = super(Subclass, self)

    def method1(self, arg):
        self.__parent.method1(arg + 2)

Python 3.14.0a1+ breaks existing code using this trick on subclasses of multiprocessing.Process.

For example:

import multiprocessing

class MyProcess(multiprocessing.Process):
    def __init__(self, target=None, args=(), kwargs={}):
        self.__parent = super(MyProcess, self)
        self.__parent.__init__(target=target, args=args, kwargs=kwargs)

    def run(self):
        self.__parent.run()
    
if __name__ == "__main__":
    p = MyProcess()
    p.start()

worked fine on previous versions, but now errors with:

Traceback (most recent call last):
  File "/home/dev-irc/Limnoria/repro.py", line 12, in <module>
    p.start()
    ~~~~~~~^^
  File "/home/dev-irc/.local-py-git/lib/python3.14/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
                  ~~~~~~~~~~~^^^^^^
  File "/home/dev-irc/.local-py-git/lib/python3.14/multiprocessing/context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/home/dev-irc/.local-py-git/lib/python3.14/multiprocessing/context.py", line 300, in _Popen
    return Popen(process_obj)
  File "/home/dev-irc/.local-py-git/lib/python3.14/multiprocessing/popen_forkserver.py", line 35, in __init__
    super().__init__(process_obj)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/home/dev-irc/.local-py-git/lib/python3.14/multiprocessing/popen_fork.py", line 20, in __init__
    self._launch(process_obj)
    ~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/home/dev-irc/.local-py-git/lib/python3.14/multiprocessing/popen_forkserver.py", line 47, in _launch
    reduction.dump(process_obj, buf)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/home/dev-irc/.local-py-git/lib/python3.14/multiprocessing/reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
_pickle.PicklingError: first argument to __newobj__() must be <class 'super'>, not <class '__main__.MyProcess'>
when serializing super object
when serializing dict item '_MyProcess__parent'
when serializing MyProcess state
when serializing MyProcess object

Full version string: Python 3.14.0a1+ (heads/main:c8fd4b12e3d, Oct 18 2024, 22:51:39) [GCC 12.2.0] on linux

CPython versions tested on:

3.14, CPython main branch

Operating systems tested on:

Linux

Linked PRs
  • gh-125750

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。