I have a C application that embeds the Python 2.7 interpreter. At some point in my program, a potentially large string (char*
) is generated and needs to be processed by some Python code. I use PyObject_CallFunction
to call the Python function and pass the string as an argument. This Python function then uses the multiprocessing
library to analyze the data in a separate process.
Passing the string to the Python function will create a copy of the data in a Python str
object. I tried to avoid this extra copy by passing a buffer
object to the Python function. Unfortunately, this generates an error in the multiprocessing
process during unpickling:
TypeError: buffer() takes at least 1 argument (0 given)
It seems as though buffer
objects can be pickled, but not unpickled.
Any suggestions on passing the char*
from C to the multiprocessing
function without making an extra copy?