[IronPython] how to generate multiple concurrent scriptign engines?
lady_radsu at yahoo.com
Thu Apr 14 09:02:32 CEST 2011
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");
string class_param = rule;
object parameters = new object;
parameters = 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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Ironpython-users