Advanced object persistence?

Nolan Darilek nolan at ethereal.dhis.org
Tue Sep 28 13:21:39 EDT 1999


Thanks to everyone who answered my Python compiler question. I have
another for 'ya. :)

I'm currently working on an online game server written in Python. One
of this server's features is that it stores all objects in a shelve,
and that it can restore objects and decompile them into a single
Python script, or a directory structure.

Or, at least, it will one day. :) In order to support user
extensibility, I need to allow for each function's code to persist
along with the object. I know there is a bytecode compiler, but is
there a decompiler which extracts functions' source from their
bytecodes, and if so, does it handle comments and docstrings?

I suspect that there isn't such an item. So, I've begun implementing
my own advanced persistence  model. Basically, it uses a standard
Object class with an objname variable so that instance names can
persist as well. It is also comprised of a list of Function
objects. Each Function stores a list of code and a bytecode
compilation, and its constructor basically runs the bytecode version
of the code. So, to run a function, you'd define a subclass of the
Function class, fill out its code variable, run a compile() method
which creates the bytecode, and instantiate it to run the code, since
the constructor calls the variable containing the function code.

So, what does everyone think about this system? I have a few concerns,
and I'd like to hear everyone's thoughts on them.

First of all, has work been done in this area? If there is already a
persistence model which retains object code and namespace names, I'll
stop working on this and start working on my true project. :)

To run each function, I'm basically instantiating an object and
dropping all references to it. Python does garbage collection,
correct? Could this practice possibly cause memory leaks? Also, can
Python constructors return values?

Or, am I going about this the wrong way? My only goals are to have
code and namespace names persist alongside objects, and to have those
names imported from a shelve (which works, currently). Is there an
easier or more elegant way to do this? It just feels as if I'm jumping
through hoops only to save user-written game code between
sessions. (Not that I mind doing it this way, but if there's a simpler
method, I'm all for it. :)

Thanks in advance.




More information about the Python-list mailing list