出现错误“TypeError:无法pickle”_cffi_backend.FFI“对象”在Python中

发布于 2025-01-18 00:32:25 字数 1985 浏览 0 评论 0原文

这个 cffi 库是通过某些依赖项安装的,现在它出现了这个错误:

File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\multiprocessing\pool.py", line 372, in 
starmap
    return self._map_async(func, iterable, starmapstar, chunksize).get()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\multiprocessing\pool.py", line 771, in 
get
    raise self._value
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\multiprocessing\pool.py", line 537, in 
_handle_tasks
    put(task)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\multiprocessing\connection.py", line 211, in send
    self._send_bytes(_ForkingPickler.dumps(obj))
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\multiprocessing\reduction.py", line 51, in dumps
    cls(buf, protocol).dump(obj)
TypeError: cannot pickle '_cffi_backend.FFI' object

出现错误的代码点是这样的:

    if parallel_process is True:
        print("Start parallel processing")
        with multiprocessing.Pool() as pool:
            boxes = pool.starmap(      <<<----- Here is where the traceback reports the error
                action,
                zip(
                    boxes,
                    repeat(var1),
                    repeat(var2),
                    repeat(var3),
                    repeat(var4),
                ),
            )

我做了一些研究,但唯一发现的是这个错误修正报告,但我不知道如何实现它: https://github.com/mcpyproject/McPy/pull/20

我的环境是 Windows 10 pro、python 3.10.4 和 cffi 1.15.0。

编辑

我发现只有当parallel_process为True时才会出现错误,否则,池不会执行,错误也不会出现。综上所述,我认为 cffi 与 python 的多处理功能不兼容。

有人知道是这样吗?

this cffi library was installed by some dependency, and now it is rising this error:

File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\multiprocessing\pool.py", line 372, in 
starmap
    return self._map_async(func, iterable, starmapstar, chunksize).get()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\multiprocessing\pool.py", line 771, in 
get
    raise self._value
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\multiprocessing\pool.py", line 537, in 
_handle_tasks
    put(task)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\multiprocessing\connection.py", line 211, in send
    self._send_bytes(_ForkingPickler.dumps(obj))
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\multiprocessing\reduction.py", line 51, in dumps
    cls(buf, protocol).dump(obj)
TypeError: cannot pickle '_cffi_backend.FFI' object

The point of the code where it is rising the error is this:

    if parallel_process is True:
        print("Start parallel processing")
        with multiprocessing.Pool() as pool:
            boxes = pool.starmap(      <<<----- Here is where the traceback reports the error
                action,
                zip(
                    boxes,
                    repeat(var1),
                    repeat(var2),
                    repeat(var3),
                    repeat(var4),
                ),
            )

I made some research, but the only thing a found was this bug correction report, but I don't know how to implement it: https://github.com/mcpyproject/McPy/pull/20

My environment is Windows 10 pro, python 3.10.4, and cffi 1.15.0.

EDIT

I found that the error only rises when parallel_process is True, otherwise, the pooling is not executed and the error doesn't rise. Summing up, I believe cffi is not compatible with the multiprocessing feature of python.

Does anybody know if this is so?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文