Hi
I beleive I have found a major issue with the jsr223 implementation of jython in 2.5.1 release - one that would cause huge issues with multithreading. I have a simple script "c=a+b" - which can be tested as a jython script or a rhino [javascript] script. The sample jsr223 code for this is as below:

ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("python");
CompiledScript cs = ((Compilable)engine).compile("c=a+b");

Ideally I would like to cache this "cs" object and use it in a multithreaded environment. So the next few lines of the code would be executed in a multithreaded env

Bindings binding = cs.getEngine().createBindings();//new SimpleBindings();
binding.put("a", a);
binding.put("b", b);


cs.eval(binding);

System.out.println(a+"+"+b+"="+binding.get("c"));

Now if I try this with the jython 2.5.1 jar it blows up right in "cs.eval(binding)" statement!!!!! [note I tried with the Bindings binding = new SimpleBindings(); - same error]

javax.script.ScriptException: NameError: name 'a' is not defined in <script> at
line number 1
at org.python.jsr223.PyScriptEngine.scriptException(PyScriptEngine.java:
182)
at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:43)
at org.python.jsr223.PyScriptEngine.access$100(PyScriptEngine.java:20)
at org.python.jsr223.PyScriptEngine$PyCompiledScript.eval(PyScriptEngine
.java:211)
at javax.script.CompiledScript.eval(CompiledScript.java:86)



Now if this same code is run with rhino [the default that comes with sun/ibm jdk] it works great.

If I tweak this code to as below

Bindings binding = cs.getEngine().createBindings();//new SimpleBindings();
binding.put("a", a);
binding.put("b", b);


ScriptContext sc = cs.getEngine().getContext();
 
sc.setBindings(binding, ScriptContext.ENGINE_SCOPE);
cs.eval(sc);//instead of the binding
 
System.out.println(a+"+"+b+"="+binding.get("c"));
 
This works great for jython - but messes up the multithreading entorely as now the Binding is really a part of the ScriptEngine => which is shared by all threads. So in effect I cannot use the CompiledScript in a multithreaded way for jython. This [multithreaded CompliedScript] works for Rhino and this is a very basic expectation - I hope somebody from Jython jsr team is polling this newsgrp to verify my claim. Is this a known bug? Did anybody face this before and knows workaround for this - I am little desparate as without this support I cannot use the CompiledScript concept => wihtout which the jython performance is pretty bad for me.
 
Any pointers is highly appreciated.
thanks
Anamitra