can't use multiprocessing with class factory?

Robert Kern robert.kern at gmail.com
Fri Jan 28 14:42:21 EST 2011


On 1/28/11 1:25 PM, Daniel Urban wrote:

> Only classes defined on the top level of a module are picklable (see
> http://docs.python.org/dev/py3k/library/pickle#what-can-be-pickled-and-unpickled
> ). The collections.namedtuple class factory function works around this
> limitation by setting the __module__  attribute of the created class,
> but I'm not sure if this solution can be used in this case.

namedtuple's trick only works when you assign the created class to a name at the 
module level. E.g.

   MyFancyTuple = collections.namedtuple(...)

The trick won't work for "anonymous" classes like the above use case.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-list mailing list