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

No members online now.

Forum statistics

Threads
473,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top