Actually I was working with exactly the object factory section that you mention. However, I think these examples are not quite production-quality code:
* http://jythonpodcast.hostjava.net/jythonbook/chapter10.html#one-to-one-jython-object-factories forces to recreate PythonInterpreter each time a new type of Jython->Java object is needed. The factory can only be reused for building several objects of same type.
* http://jythonpodcast.hostjava.net/jythonbook/chapter10.html#making-use-of-a-loosely-coupled-object-factory : The upper listing recreates PythonInterpreter each time a new Jython->Java object is needed - it's doesn't even reuse the interpreter for same types of objects (like the previous example does). The lower one (that uses PySystemState) contains the descriptive comment: "// likely want to reuse PySystemState in some clever fashion since expensive to setup..."
So from the doc it seems that nobody has really figured out how to actually implement this reuse thing. Anyway, thanks for pointing out PlyJy in the other mail, I'll have a look at it.
It seems that the only way to really "reset" the interpreter would be to recreate it as you mention. I do agree with you that cleanup() seems that it should do the trick...but instead does nothing notable.
Can we ask what you are doing with the interpreter? Are object factories (http://jythonpodcast.hostjava.net/jythonbook/chapter10.html#object-factories) a solution that may work for you? If so, they are quite easy to use and there is a PySystemState object factory that performs fairly well. This may be something for you to look into. You may also want to take a look at using JSR-223 as it may do the trick for you.Best
Twitter ID: javajuneau
On Fri, Nov 6, 2009 at 6:48 AM, Joonas Pulakka <email@example.com> wrote:
------------------------------------------------------------------------------Hello,I've been told that creating a PythonInterpreter object is relatively expensive, and therefore it makes sense to cache/reuse it somehow. However, I'm having difficulties to "reset" the interpreter to its initial state. By resetting I mean clearing all previous variables, functions and class definitions. I thought interp.cleanup() would do something like that, but it doesn't seem to have any effect.Is there a way to "reset" the interpreter, or should I just recreate it?Best Regards,Joonas
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
Jython-users mailing list