Getting error "TypeError: cannot pickle '_cffi_backend.FFI' object" in Python

Viewed 936

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?

0 Answers
Related