[IronPython] how to generate multiple concurrent scriptign engines?

Jeff Hardy jdhardy at gmail.com
Thu Apr 14 16:35:53 CEST 2011


As long as you have a ScriptScope per thread, you should be able to
share the ScriptEngine & Runtime between threads.

What is the exception that you are getting? If it's a GUI program,
remember that UI elements can only be manipulated from the main
thread.

- Jeff

On Thu, Apr 14, 2011 at 1:02 AM, surangika ranathunga
<lady_radsu at yahoo.com> wrote:
>
> Hi,
> I am using Ironpython to connect to a legacy python code from C#.
> I am not fully familiar with Ironpython, but managed to get it working for a single-threaded application.
> This is how I implemented this:
>
>                 ScriptEngine engine = Python.CreateEngine();
>                 ScriptRuntime runtime = engine.Runtime;
>                 ScriptScope scope = runtime.CreateScope();
>                 ops = engine.Operations;
>                 ScriptSource source = engine.CreateScriptSourceFromFile("ironpython.py");
>                 source.Execute(scope);
>                 string class_param = rule;
>                 object[] parameters = new object[1];
>                 parameters[0] = class_param;
>                 object klass = scope.GetVariable("model_checker");
>                 object instance = ops.Invoke(klass, parameters);
>                 method = ops.GetMember(instance, "check_model");
>
> Now I want to make my application multi-threaded, and I want to have concurrently running scripting engines. Essentially, these engines should access the same underlying python code, and hence these scripting engines are identical to each other.
> Without any change, the above code works fine for most of the time for a multi-threaded application. However, there is an exception that appears from time to time, and I suspect that it is due to a concurrency issue.
>
> Is there anything specific that I should do to generate multiple scripting engines running in separate threads without interfering with each other?
>
> any ideas greatly appreciated
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>



More information about the Ironpython-users mailing list