Thanks so much Pierre & Jeff!

Jeff, did you mean that I should do something like below to create a PythonInterpreter?

 PythonInterpreter interpreter = new PythonInterpreter(new PyStringMap(), new PySystemState());

Thanks!

Li

2011/11/4 Jeff Emanuel <jemanuel@frii.com>

The interpreters ought to be constructed with independent
namespaces and sys modules, otherwise they are shared among
interpreters.  See the 2-arg constuctor.

http://www.jython.org/javadoc/org/python/util/PythonInterpreter.html#PythonInterpreter(org.python.core.PyObject,
org.python.core.PySystemState)

Pierre Thibault wrote:
> 2011/11/3 Li Shen <lis365@gmail.com <mailto:lis365@gmail.com>>
>
>     Hi,
>
>     I'm pretty new to jython and I want to use jython to execute many
>     existing python scripts.
>
>     For performance reason, I'm wondering if I can pre-compile the
>     python scripts, like below:
>
>     private PyCode code = new PythonInterpreter().compile((new
>     InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(SCRIPT_NAME))));
>
>     And then reuse the compiled code in a multi-thread environment,
>     like below:
>
>     public void someMethod() {
>         PythonInterpreter interpreter = new PythonInterpreter();
>         interpreter.exec(code);
>         // ...
>     }
>
>     Looks like the doc doesn't mention if PyCode is thead-safe. Could
>     anyone please give out some clarifications, or suggestions if this
>     approach is incorrect.
>
>     Thanks!
>
>
>
> I think so. Each PythonInterpreter is an independent state machine.
>
> Pierre Thibault
>
> Python Developer/Développeur Python
> Montréal, QC
> /pierre.thibault1@gmail.com <mailto:pierre.thibault1@gmail.com>/
>
>
>
>
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> RSA(R) Conference 2012
> Save $700 by Nov 18
> Register now
> http://p.sf.net/sfu/rsa-sfdev2dev1
> ------------------------------------------------------------------------
>
> _______________________________________________
> Jython-users mailing list
> Jython-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jython-users
>

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users