Creating a python extension that works with multiprocessing.Queue

Travis Miller raphtee at
Sun Mar 15 04:51:35 CET 2009

I am very new to the python C API, and have written a simple type
called SU2 that has 4 members that are all doubles.  Everything seems
to work fine (can import my module and instantiate the new type and
act on it with various methods I have defined), except for when I
attempt to use my new type with multiprocessing.Queue (by the way I am
working with python 2.6).

So when I declare my object instance and call the put() method on the
Queue instance, the object I get out with the get() method of the same
Queue instance is not the same object.   The four members of the
object are all coming through as all zeros.  Below is the snippet of

from multiprocessing import Queue, Process
from gauge import SU2       # this is my new module and type

def func(q):
    s = SU2(1.0, 2.0, 3.0, 4.0)

q = Queue()
p = Process(target=func, args=(q,))
s = q.get()

The problem is that the s I get in the get() method has its members
set to 0.0 rather than what I set in func().  So the members are not
being put in the Queue correctly.  I have defined the SU2 type using
the python C API and so I suspect I have neglected to define a method
that is needed by Queue to do its stuff.  What am I missing?

Travis Miller

More information about the Python-list mailing list