saving pre-compiled scripts

D

Derek van Vliet

Hi,

I'm working on an application that reads python scripts from XML
elements and compiles them during my app's startup process using. The
application then runs the resulting compiled PyCodeObjects using
PyEval_EvalCode as they are needed.

Now I'm wondering if its possible to pre-compile the scripts and save
the PyCodeObjects in a binary file (or in CDATA in an XML element) and
have them ready to run when the application starts up.

My only constraint is that I need to be able to load the scripts from
memory (which is why using Py_CompileString has worked well for me).

Is there any way I can get the size of a PyCodeObject so that I could
save it to a binary file? If I did that would it run correctly if I
reloaded it and tried to Eval it? Can I load a pyc file from memory
somehow?

Any guidance would be greatly appreciated.

Thanks,
Derek
 
D

Derek van Vliet

Another thing which may be important to note re: my constraints is that
each script is essentially being run as a function.

In fact, every script element I parse in XML gets wrapped in a function
def before I send it to Py_CompileString.

I then PyEval the result of that function, and then run
Py_CompileString again, passing only the automatically generated
function call.

The result of the second Py_CompileString is what I pass to
PyEval_EvalCode whenever my app needs to run that script (function).
 
D

Derek van Vliet

I probably should have also mentioned that my application is written in
C++ and using the Python/C API.
 

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,020
Latest member
GenesisGai

Latest Threads

Top