[IronPython] Multiple engines, multiple scopes

Curt Hagenlocher curt at hagenlocher.org
Sat Mar 29 21:41:21 CET 2008


Beta 1 now supports multiple engines inside the same AppDomain
provided that you create a ScriptRuntime for each:
    ScriptEngine engine1 = ScriptRuntime.Create().GetEngine("py");
    ScriptEngine engine2 = ScriptRuntime.Create().GetEngine("py");

A ScriptScope is loosely equivalent to a Python module.  Empty
ScriptScopes can be created from the engine:
    ScriptScope scope1 = engine1.CreateScope();
    ScriptScope scope2 = engine2.CreateScope();

So the ScriptScope is somewhat bound to the engine it was created
from.  But in actuality, the engine is only used for
ScriptScope.GetVariable<T>, and the other operations on ScriptScope
appear to be entirely independent of the ScriptEngine.

In particular, scope1.GetVariable<int>("foo") is equivalent to
engine1.GetVariable<int>(scope1, "foo").  But it appears to be quite
legal to say engine2.GetVariable<int>(scope1, "foo")
engine2.GetVariable<int>(scope1, "foo"), and the only difference
appears to be the context that's used for the type conversion -- if
needed.

Is this intentional?  It seems to me that it would be better if the
ScriptScope were either more tightly bound to the ScriptEngine or not
bound to it at all.

--
Curt Hagenlocher
curt at hagenlocher.org



More information about the Ironpython-users mailing list