Help with Code Object Caching

Brent Fulgham brent.fulgham at xpsystems.com
Mon Feb 28 12:26:01 EST 2000


I'm in the process of trying to add Python support to an
existing web server.  The first step I took was to imbed
a Python interpreter, and have it execute scripts in a
CGI-ish fashion (just without the overhead of starting a
new process to run).  (BTW -- this server is written
in C, so I am working heavily with the C API)

The initial implementation would cache the contents of
the *.py file in a cache (which has certain rules about
when it may be swapped out to the hard disk, etc.), which
is useful for performance reasons.

Instead of caching the script contents, I am now trying to
cache the compiled code object so it can just be reused
without having to take the py->compiled object hit every
time a script is invoked.

My initial implementation is to Marshal the compiled code
object into a PyString, then convert this into a "char*"
of known length I can store in my Cache.

Then, when I am ready to execute, I build a new PyString
from the char* and length, Marshal it back to a PyCodeObject,
and execute that.

Before I go too far down this path, I just wanted to ask
if there were any better alternatives that have already
been implemented.  This seems like a problem that might have
been solved by others already.

Any comments?

Thanks,

-Brent




More information about the Python-list mailing list