Creating a python extension that works with multiprocessing.Queue

Travis Miller raphtee at
Fri Mar 20 03:16:29 CET 2009

I'm on linux actually.  I found that so long as I implement
__reduce__, then pickling works, and my extension works with Queue
objects correctly.  So far the C Api is really cool.  I can do all the
math stuff where I need the speed, and still be able to use python
which is way more expressive.


On Mar 17, 8:43 pm, "Gabriel Genellina" <gagsl-... at>
> En Sun, 15 Mar 2009 01:51:35 -0200, Travis Miller <raph... at>  
> escribió:
> > 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
> > code.
> Are you on Windows? multiprocessing uses pickles to transfer objects  
> between processes. See if you can dump and load those kind of objects. If  
> not, you may need to implement __getstate__/__setstate__ or __reduce__
> See
> --
> Gabriel Genellina

More information about the Python-list mailing list