Re: compile, marshal, exec

"Fernando" <[email protected]>
Newsgroups gmane.comp.lang.jython.user
Message-ID <1431353677284.49161.22384@webmail4>
On 11 May 2015, Alan Kennedy <[email protected]> wrote:
> [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.
> 
> I am using pyservlet to call my own jython servlet and in here I would run the code above. I don't see the need for extra interpreters, right?


> 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>
> 
> thks, I looked at it already but I don't have experience with java and its libraries. If I get a decently working solution then I could look into porting my jython servlet to java, but I am really not looking forward to it. For now I am merely seeing if there is any major roadblock.

The reason for 'compile' is to persist the byte code for a quicker startup. Sadly, marshall in jython does not seem to be working well.


> > 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.
> 
> Thanks for your extensice feedback 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.