出现错误“TypeError:无法pickle”_cffi_backend.FFI“对象”在Python中
这个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论