Re: compile, marshal, exec

Alan Kennedy <[email protected]>
Newsgroups gmane.comp.lang.jython.user
Message-ID <CAMte6hkbFA0_5fmcL7Dur1bQs-3oqfiwB7wdsg8cSjgw7B4LTg@mail.gmail.com>
[Fernando]
> >>> f = file('dateGetYmd') # the script file, which has a namesake
function
> >>> obj = compile(f.read(), '', 'exec')
> >>> marshal.dump(obj, fc)
> >>> exec obj
> >>> dateGetYmd('0') # this function call will also access local objects

> Would this work in Jython? docs would say so, but is there any caveats?

There should no problem with this. Obviously, the file containing the
source must be acessible to the servlet context you are running it from.

You could execute the jython source listed above directly in an embedded
jython interpreter, meaning you would represent it as a string, and pass it
to the 'exec' method of a org.python.util.PythonInterpreter.

Or you could figure out the equivalent java calls, and invoke them directly
from java.

PyServlet gives a good example of how to write all the relevant code, in
java.

I would use 'execfile' instead of 'compile', which applies to both java
code and jython. Here is where PyServlet does it

https://hg.python.org/jython/file/6855fa289d48/src/org/python/util/PyServlet.java#l208

> and what about performance? what does compile return? (python byte codes?)

Compile (and exec and execfile) return JVM bytecode representing the jython
source. The performance of running this code in an embedded context should
be the same as running in a non-embedded context.

> Or is there a better way to do it?

Not necessarily better, but an alternative to using PyServlet is to use
modjy, which would give you WSGI compatibility, and better configurability.

Alan.

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y

_______________________________________________
Jython-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jython-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.