Pickling dynamically generated classes

G

George Sakkis

The Fine Manual mentions that pickle works for classes that are
defined at the top level of a module. Is there a way to extend this
behavior so that I can pickle and unpickle instances of dynamically
generated classes ?

Longer version: I have a function RecordTypeFactory(fields, ...) that
dynamically generates and caches a record-like class based on the
passed fields and other info (or returns the cached class if it has
been created before). Although I am able to pickle instances of the
various generated classes (records) by writing the gen. class in
globals(), I cannot unpickle them from a different process unless
RecordTypeFactory is called with the same arguments so that "the same"
class is generated in the other process as well. Essentially what I'm
missing is a hook to call RecordTypeFactory with the same fields when
an instance of the gen. class is to be unpickled.

George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top